diff options
author | 2010-07-30 00:02:09 +0200 | |
---|---|---|
committer | 2010-07-30 00:02:09 +0200 | |
commit | 922e6955a4628ab7c94c9540f28bbc44b3e6a96c (patch) | |
tree | 6c403479ce9e960b527fb70566ffbcf778e876b8 | |
parent | Initial library commit (diff) | |
download | c-portage-922e6955a4628ab7c94c9540f28bbc44b3e6a96c.tar.gz c-portage-922e6955a4628ab7c94c9540f28bbc44b3e6a96c.tar.bz2 c-portage-922e6955a4628ab7c94c9540f28bbc44b3e6a96c.zip |
Implement data_connect functions and the PortageSettings class
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | Makefile.in | 19 | ||||
-rwxr-xr-x | libtool | 2 | ||||
-rw-r--r-- | src/dataconnect.c | 375 | ||||
-rw-r--r-- | src/dataconnect.h | 31 | ||||
-rw-r--r-- | src/interpreter.c | 3 | ||||
-rw-r--r-- | src/portage.h | 4 | ||||
-rw-r--r-- | src/portagesettings.c | 276 | ||||
-rw-r--r-- | src/portagesettings.h | 36 | ||||
-rw-r--r-- | src/stringlist.c | 16 | ||||
-rw-r--r-- | src/tester.c | 55 |
11 files changed, 779 insertions, 44 deletions
diff --git a/Makefile.am b/Makefile.am index fe9eaed..7734973 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,13 +2,13 @@ AUTOMAKE_OPTIONS = subdir-objects ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} lib_LTLIBRARIES = libportage.la -AM_CFLAGS = $(PYTHON_CFLAGS) --std=c99 -W -Wall +AM_CFLAGS = $(PYTHON_CFLAGS) --std=c99 -W -Wall -O0 -g -libportage_la_SOURCES = src/dict.c src/interpreter.c src/stringlist.c +libportage_la_SOURCES = src/dataconnect.c src/portagesettings.c src/dict.c src/interpreter.c src/stringlist.c libportage_la_LIBADD = $(PYTHON_LIBS) portage_includedir = $(includedir)/portage -portage_include_HEADERS = src/portage.h src/dict.h src/interpreter.h src/stringlist.h +portage_include_HEADERS = src/dataconnect.h src/portagesettings.h src/portage.h src/dict.h src/interpreter.h src/stringlist.h #bin_PROGRAMS = tester diff --git a/Makefile.in b/Makefile.in index eb6471b..e075e95 100644 --- a/Makefile.in +++ b/Makefile.in @@ -77,8 +77,8 @@ LTLIBRARIES = $(lib_LTLIBRARIES) am__DEPENDENCIES_1 = libportage_la_DEPENDENCIES = $(am__DEPENDENCIES_1) am__dirstamp = $(am__leading_dot)dirstamp -am_libportage_la_OBJECTS = src/dict.lo src/interpreter.lo \ - src/stringlist.lo +am_libportage_la_OBJECTS = src/dataconnect.lo src/portagesettings.lo \ + src/dict.lo src/interpreter.lo src/stringlist.lo libportage_la_OBJECTS = $(am_libportage_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -225,11 +225,11 @@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = subdir-objects ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} lib_LTLIBRARIES = libportage.la -AM_CFLAGS = $(PYTHON_CFLAGS) --std=c99 -W -Wall -libportage_la_SOURCES = src/dict.c src/interpreter.c src/stringlist.c +AM_CFLAGS = $(PYTHON_CFLAGS) --std=c99 -W -Wall -O0 -g +libportage_la_SOURCES = src/dataconnect.c src/portagesettings.c src/dict.c src/interpreter.c src/stringlist.c libportage_la_LIBADD = $(PYTHON_LIBS) portage_includedir = $(includedir)/portage -portage_include_HEADERS = src/portage.h src/dict.h src/interpreter.h src/stringlist.h +portage_include_HEADERS = src/dataconnect.h src/portagesettings.h src/portage.h src/dict.h src/interpreter.h src/stringlist.h all: all-am .SUFFIXES: @@ -307,6 +307,9 @@ src/$(am__dirstamp): src/$(DEPDIR)/$(am__dirstamp): @$(MKDIR_P) src/$(DEPDIR) @: > src/$(DEPDIR)/$(am__dirstamp) +src/dataconnect.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) +src/portagesettings.lo: src/$(am__dirstamp) \ + src/$(DEPDIR)/$(am__dirstamp) src/dict.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/interpreter.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/stringlist.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) @@ -315,18 +318,24 @@ libportage.la: $(libportage_la_OBJECTS) $(libportage_la_DEPENDENCIES) mostlyclean-compile: -rm -f *.$(OBJEXT) + -rm -f src/dataconnect.$(OBJEXT) + -rm -f src/dataconnect.lo -rm -f src/dict.$(OBJEXT) -rm -f src/dict.lo -rm -f src/interpreter.$(OBJEXT) -rm -f src/interpreter.lo + -rm -f src/portagesettings.$(OBJEXT) + -rm -f src/portagesettings.lo -rm -f src/stringlist.$(OBJEXT) -rm -f src/stringlist.lo distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dataconnect.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dict.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/interpreter.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/portagesettings.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/stringlist.Plo@am__quote@ .c.o: @@ -86,7 +86,7 @@ NM="/usr/bin/nm -B" LN_S="ln -s" # What is the maximum length of a command? -max_cmd_len=1572864 +max_cmd_len=3458764513820540925 # Object file suffix (normally "o"). objext=o diff --git a/src/dataconnect.c b/src/dataconnect.c new file mode 100644 index 0000000..63d0e1a --- /dev/null +++ b/src/dataconnect.c @@ -0,0 +1,375 @@ +#include "internal.h" +#include "dataconnect.h" + +StringList* portageGetVersions(const char *pkg, int include_masked) +{ + PyObject *obj = executeFunction("portage.api.data_connect", "get_versions", "(zI)", pkg, include_masked); + if (!obj || !PySequence_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + StringList *ret = listToCList(obj); + + Py_DECREF(obj); + + return ret; +} + +//int portageGetHardMasked(const char*) +//{ +//} + +StringList* portageGetInstalledFiles(const char *pkg) +{ + PyObject *obj = executeFunction("portage.api.data_connect", "get_installed_files", "(z)", pkg); + if (!obj || !PySequence_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + StringList *ret = listToCList(obj); + + Py_DECREF(obj); + + return ret; +} + + +char* portageBestVersion(StringList *pkgs) +{ + assert(pkgs); + PyObject *pylist = cListToPyList(pkgs); + PyObject *obj = executeFunction("portage.api.data_connect", "best_version", "(O)", pylist); + Py_DECREF(pylist); + if (!obj || !PyString_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + char *ret = strdup(PyString_AsString(obj)); + Py_DECREF(obj); + + return ret; +} + +char* portageGetBestEbuild(const char *pkg) +{ + assert(pkg); + PyObject *obj = executeFunction("portage.api.data_connect", "get_best_ebuild", "(z)", pkg); + if (!obj || !PyUnicode_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + PyObject *tmp = PyUnicode_AsUTF8String(obj); + char *ret = strdup(PyString_AsString(tmp)); + + Py_DECREF(tmp); + Py_DECREF(obj); + + return ret; +} + +//FIXME:what does it return exactly ? +char* portageGetDepEbuild(const char *pkg) +{ + assert(pkg); + PyObject *obj = executeFunction("portage.api.data_connect", "get_dep_ebuild", "(z)", pkg); + if (!obj || !PyUnicode_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + PyObject *tmp = PyUnicode_AsUTF8String(obj); + char *ret = strdup(PyString_AsString(tmp)); + + Py_DECREF(tmp); + Py_DECREF(obj); + + return ret; +} + + +//FIXME:are values always strings/unicodes ? +StringList* portageGetMaskingStatus(const char *pkg) +{ + assert(pkg); + PyObject *obj = executeFunction("portage.api.data_connect", "get_masking_status", "(z)", pkg); + if (!obj || !PySequence_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + StringList *ret = listToCList(obj); + + Py_DECREF(obj); + + return ret; +} + +char* portageGetMaskingReason(const char *pkg) +{ + assert(pkg); + PyObject *obj = executeFunction("portage.api.data_connect", "get_masking_reason", "(z)", pkg); + if (!obj || !PyUnicode_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + PyObject *tmp = PyUnicode_AsUTF8String(obj); + char *ret = strdup(PyString_AsString(tmp)); + + Py_DECREF(tmp); + Py_DECREF(obj); + + return ret; +} + + +long int portageGetPackageSizeInt(const char *pkg) +{ + assert(pkg); + PyObject *obj = executeFunction("portage.api.data_connect", "get_size", "(zI)", pkg, 0); + if (!obj || !PyLong_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return 0; + } + + long int ret = PyLong_AsLong(obj); + + Py_DECREF(obj); + + return ret; +} + +char* portageGetPackageSizeString(const char *pkg) +{ + assert(pkg); + PyObject *obj = executeFunction("portage.api.data_connect", "get_size", "(z)", pkg); + if (!obj || !PyString_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + char* ret = strdup(PyString_AsString(obj)); + + Py_DECREF(obj); + + return ret; +} + +//FIXME:str object is not callable. +//void portageGetProperties(const char*) +//{ +//} + +int portageIsOverlay(const char *pkg) +{ + assert(pkg); + PyObject *obj = executeFunction("portage.api.data_connect", "is_overlay", "(z)", pkg); + if (!obj) + return 0; + + int ret = PyObject_IsTrue(obj); + + Py_DECREF(obj); + + return ret; +} + +char* portageGetOverlay(const char *pkg) +{ + assert(pkg); + PyObject *obj = executeFunction("portage.api.data_connect", "get_overlay", "(z)", pkg); + if (!obj || !PyUnicode_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + PyObject *tmp = PyUnicode_AsUTF8String(obj); + char *ret = strdup(PyString_AsString(tmp)); + + Py_DECREF(tmp); + Py_DECREF(obj); + + return ret; +} + +char* portageGetOverlayNameFromPath(const char *path) +{ + assert(path); + PyObject *obj = executeFunction("portage.api.data_connect", "get_overlay_name", "(z)", path); + if (!obj || !PyUnicode_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + PyObject *tmp = PyUnicode_AsUTF8String(obj); + char *ret = strdup(PyString_AsString(tmp)); + + Py_DECREF(tmp); + Py_DECREF(obj); + + return ret; +} + +char* portageGetOverlayNameFromPkg(const char *pkg) +{ + assert(pkg); + PyObject *none = Py_None; + Py_INCREF(none); + PyObject *obj = executeFunction("portage.api.data_connect", "get_overlay_name", "(Oz)", none, pkg); + Py_DECREF(none); + if (!obj || !PyUnicode_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + PyObject *tmp = PyUnicode_AsUTF8String(obj); + char *ret = strdup(PyString_AsString(tmp)); + + Py_DECREF(tmp); + Py_DECREF(obj); + + return ret; +} + +//char* portageGetPath(const char*, int) +//{ +//} + + +StringList* portageGetResolvedPkgs() +{ + PyObject *obj = executeFunction("portage.api.data_connect", "get_system_pkgs", NULL); + if (!obj || !PySequence_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + PyObject *resolved = PySequence_GetItem(obj, 0); + if (!resolved) + return NULL; + + StringList *ret = listToCList(resolved); + + Py_DECREF(resolved); + Py_DECREF(obj); + + return ret; +} + +StringList* portageGetUnresolvedPkgs() +{ + PyObject *obj = executeFunction("portage.api.data_connect", "get_system_pkgs", NULL); + if (!obj || !PySequence_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + PyObject *unresolved = PySequence_GetItem(obj, 1); + if (!unresolved) + return NULL; + + StringList *ret = listToCList(unresolved); + + Py_DECREF(unresolved); + Py_DECREF(obj); + + return ret; +} + +StringList* portageGetAllNodes() +{ + PyObject *obj = executeFunction("portage.api.data_connect", "get_all_nodes", NULL); + if (!obj || !PySequence_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + StringList *ret = listToCList(obj); + + Py_DECREF(obj); + + return ret; +} + +StringList* portageGetInstalledList() +{ + PyObject *obj = executeFunction("portage.api.data_connect", "get_installed_list", NULL); + if (!obj || !PySequence_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return NULL; + } + + StringList *ret = listToCList(obj); + + Py_DECREF(obj); + + return ret; +} diff --git a/src/dataconnect.h b/src/dataconnect.h new file mode 100644 index 0000000..cc990be --- /dev/null +++ b/src/dataconnect.h @@ -0,0 +1,31 @@ +#ifndef DATACONNECT_H +#define DATACONNECT_H + +#include "stringlist.h" + +StringList* portageGetVersions(const char*, int); +//int portageGetHardMasked(const char*); +StringList* portageGetInstalledFiles(const char*); + +char* portageBestVersion(StringList*); +char* portageGetBestEbuild(const char*); +char* portageGetDepEbuild(const char*); + +StringList* portageGetMaskingStatus(const char*); +char* portageGetMaskingReason(const char*); + +long int portageGetPackageSizeInt(const char*); +char* portageGetPackageSizeString(const char*); +//void portageGetProperties(const char*); +int portageIsOverlay(const char*); +char* portageGetOverlay(const char*); +char* portageGetOverlayNameFromPath(const char*); +char* portageGetOverlayNameFromPkg(const char*); +//char* portageGetPath(const char*, int); + +StringList* portageGetResolvedPkgs(); +StringList* portageGetUnresolvedPkgs(); +StringList* portageGetAllNodes(); +StringList* portageGetInstalledList(); + +#endif diff --git a/src/interpreter.c b/src/interpreter.c index 941d2b2..90be58f 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -155,7 +155,10 @@ PyObject *executeFunction(const char *module, const char *funcName, const char* { mod = PyImport_ImportModule(module); if (!mod) + { + printf("Module not found.\n"); return NULL; + } insert(in->modules, mod); } diff --git a/src/portage.h b/src/portage.h index 374c721..e7ecfb9 100644 --- a/src/portage.h +++ b/src/portage.h @@ -3,6 +3,8 @@ #include "stringlist.h" #include "dict.h" -//#include "interpreter.h" +#include "portagesettings.h" +#include "dataconnect.h" +#include "interpreter.h" #endif diff --git a/src/portagesettings.c b/src/portagesettings.c new file mode 100644 index 0000000..b6d9d07 --- /dev/null +++ b/src/portagesettings.c @@ -0,0 +1,276 @@ +#include "internal.h" +#include "portagesettings.h" + +struct PortageSettings +{ + PyObject *object; +}; + +PortageSettings *portageSettingsCreate() +{ + PyObject *obj = executeFunction("portage.api.settings", "PortageSettings", NULL); + + // Call failed, library was not found. + if (!obj) + return NULL; + + PortageSettings *ret = malloc(sizeof(PortageSettings)); + ret->object = obj; + + return ret; +} + +int portageSettingsResetUseFlags(PortageSettings *ps) +{ + assert(ps); + PyObject *ret = PyObject_CallMethod(ps->object, "reset_use_flags", NULL); + + return ret != NULL; +} + +int portageSettingsReset(PortageSettings *ps) +{ + assert(ps); + PyObject *ret = PyObject_CallMethod(ps->object, "reset", NULL); + + return ret != NULL; +} + +int portageSettingsReloadConfig(PortageSettings *ps) +{ + assert(ps); + PyObject *ret = PyObject_CallMethod(ps->object, "reload_config", NULL); + + return ret != NULL; +} + +int portageSettingsReloadWorld(PortageSettings *ps) +{ + assert(ps); + PyObject *ret = PyObject_CallMethod(ps->object, "reload_world", NULL); + + return ret != NULL; +} + +StringList* portageSettingsGetWorld(PortageSettings *ps) +{ + assert(ps); + PyObject *obj = PyObject_CallMethod(ps->object, "get_world", NULL); + + if (!obj) + return NULL; + + StringList *ret = listToCList(obj); + Py_DECREF(obj); + + return ret; +} + +StringList* portageSettingsGetArchList(PortageSettings *ps) +{ + assert(ps); + PyObject *obj = PyObject_CallMethod(ps->object, "get_archlist", NULL); + + if (!obj) + return NULL; + + StringList *ret = listToCList(obj); + Py_DECREF(obj); + + return ret; +} + +StringList* portageSettingsGetVirtuals(PortageSettings *ps) +{ + assert(ps); + PyObject *obj = PyObject_CallMethod(ps->object, "get_virtuals", NULL); + + if (!obj) + return NULL; + + StringList *ret = listToCList(obj); + Py_DECREF(obj); + + return ret; +} + +char* portageSettingsAcceptKeywords(PortageSettings *ps) +{ + assert(ps); + PyObject *obj = PyObject_GetAttrString(ps->object, "ACCEPT_KEYWORDS"); + if (!obj) + { + return NULL; + } + + if (!PyUnicode_Check(obj)) + { + Py_DECREF(obj); + return NULL; + } + + PyObject *tmp = PyUnicode_AsUTF8String(obj); + char *ret = strdup(PyString_AsString(tmp)); + + Py_DECREF(tmp); + Py_DECREF(obj); + + return ret; +} + +StringList* portageSettingsSystemUseFlags(PortageSettings *ps) +{ + assert(ps); + PyObject *obj = PyObject_GetAttrString(ps->object, "SystemUseFlags"); + if (!obj) + { + return NULL; + } + + if (!PySequence_Check(obj)) + { + Py_DECREF(obj); + return NULL; + } + + StringList *ret = listToCList(obj); + + Py_DECREF(obj); + + return ret; +} + +/*void portageSettingsUseFlagDict(); +{ + assert(ps); + PyObject *obj = PyObject_GetAttrString(ps->object, "UseFlagDict"); + if (!obj) + { + return NULL; + } + + if (!PyUnicode_Check(obj)) + { + Py_DECREF(obj); + return NULL; + } + + PyObject *tmp = PyUnicode_AsUTF8String(obj); + char *ret = strdup(PyString_AsString(tmp)); + + Py_DECREF(tmp); + Py_DECREF(obj); + + return ret; +}*/ + +char* portageSettingsArch(PortageSettings *ps) +{ + assert(ps); + PyObject *obj = PyObject_GetAttrString(ps->object, "arch"); + if (!obj) + { + return NULL; + } + + if (!PyUnicode_Check(obj)) + { + Py_DECREF(obj); + return NULL; + } + + PyObject *tmp = PyUnicode_AsUTF8String(obj); + char *ret = strdup(PyString_AsString(tmp)); + + Py_DECREF(tmp); + Py_DECREF(obj); + + return ret; +} + +char* portageSettingsPortdir(PortageSettings *ps) +{ + assert(ps); + PyObject *obj = PyObject_GetAttrString(ps->object, "portdir"); + if (!obj) + { + return NULL; + } + + if (!PyUnicode_Check(obj)) + { + Py_DECREF(obj); + return NULL; + } + + PyObject *tmp = PyUnicode_AsUTF8String(obj); + char *ret = strdup(PyString_AsString(tmp)); + + Py_DECREF(tmp); + Py_DECREF(obj); + + return ret; +} + +char* portageSettingsPortdirOverlay(PortageSettings *ps) +{ + assert(ps); + PyObject *obj = PyObject_GetAttrString(ps->object, "portdir_overlay"); + if (!obj) + { + return NULL; + } + + if (!PyUnicode_Check(obj)) + { + Py_DECREF(obj); + return NULL; + } + + PyObject *tmp = PyUnicode_AsUTF8String(obj); + char *ret = strdup(PyString_AsString(tmp)); + + Py_DECREF(tmp); + Py_DECREF(obj); + + return ret; +} + +char* portageSettingsUserConfigDir(PortageSettings *ps) +{ + assert(ps); + PyObject *obj = PyObject_GetAttrString(ps->object, "user_config_dir"); + if (!obj) + { + return NULL; + } + + char *ret = NULL; + + if (PyUnicode_Check(obj)) + { + PyObject *tmp = PyUnicode_AsUTF8String(obj); + ret = strdup(PyString_AsString(tmp)); + Py_DECREF(tmp); + } + else if (PyString_Check(obj)) + { + ret = PyString_AsString(obj); + } + + + Py_DECREF(obj); + + return ret; +} + +void portageSettingsFree(PortageSettings* ps) +{ + if (ps && ps->object) + { + Py_DECREF(ps->object); + } + + if (ps) + free(ps); +} diff --git a/src/portagesettings.h b/src/portagesettings.h new file mode 100644 index 0000000..7e9b2cf --- /dev/null +++ b/src/portagesettings.h @@ -0,0 +1,36 @@ +#ifndef PORTAGE_SETTINGS_H +#define PORTAGE_SETTINGS_H + +#include "stringlist.h" + +typedef struct PortageSettings PortageSettings; + +PortageSettings *portageSettingsCreate(); + + +// Reimplemented methods. +// Those are simple calls to the python methods. + +int portageSettingsResetUseFlags(PortageSettings*); +int portageSettingsReset(PortageSettings*); +int portageSettingsReloadConfig(PortageSettings*); +int portageSettingsReloadWorld(PortageSettings*); +StringList* portageSettingsGetWorld(PortageSettings*); +StringList* portageSettingsGetArchList(PortageSettings*); +StringList* portageSettingsGetVirtuals(PortageSettings*); + +// Fields access. +// Those are functions used to access different fields of the PortageSetting object. +//'ACCEPT_KEYWORDS', 'SystemUseFlags', 'UseFlagDict', 'arch', 'portdir', 'portdir_overlay', 'user_config_dir' +char* portageSettingsAcceptKeywords(PortageSettings*); +StringList* portageSettingsSystemUseFlags(PortageSettings*); +//void portageSettingsUseFlagDict(); +char* portageSettingsArch(PortageSettings*); +char* portageSettingsPortdir(PortageSettings*); +char* portageSettingsPortdirOverlay(PortageSettings*); +char* portageSettingsUserConfigDir(PortageSettings*); + + +void portageSettingsFree(PortageSettings*); + +#endif diff --git a/src/stringlist.c b/src/stringlist.c index 915cca4..ad1acf3 100644 --- a/src/stringlist.c +++ b/src/stringlist.c @@ -72,8 +72,20 @@ StringList* listToCList(PyObject* list) //Item are copied so that the PyObject can be deleted after the call without //destroying the data in the returned list. PyObject *elem = PyList_GetItem(list, i); - ret->list[i] = malloc(sizeof(char) * (PyBytes_Size(elem) + 1)); - strcpy(ret->list[i], PyBytes_AsString(elem)); + char *val = NULL; + + if (PyUnicode_Check(elem)) + { + PyObject *tmp = PyUnicode_AsUTF8String(elem); + val = strdup(PyString_AsString(tmp)); + Py_DECREF(tmp); + } + else if (PyString_Check(elem)) + { + val = PyString_AsString(elem); + } + + ret->list[i] = strdup(val); } return ret; diff --git a/src/tester.c b/src/tester.c index 02e43df..fee6ca5 100644 --- a/src/tester.c +++ b/src/tester.c @@ -1,5 +1,7 @@ #include <stdlib.h> -#include "interpreter.h" +#include <stdio.h> + +#include "portage.h" int main(int argc, char *argv[]) { @@ -7,43 +9,32 @@ int main(int argc, char *argv[]) argv = argv; int ret = 0; portageInit(); - - /*Message *msg = messageCreate("portage", 0, 0, 0); - BareConfig *cfg = bareConfigCreate(msg, 0, 0, 0); - - LaymanAPI *l = portageAPICreate(cfg, 0, 0); - if (0 == portageAPIFetchRemoteList(l)) - { - printf("Unable to fetch the remote list.\n"); - ret = -1; - } - StringList *strs = portageAPIGetAvailable(l, 0); - printf("list:\n"); - stringListPrint(strs); + PortageSettings *ps = portageSettingsCreate(); + StringList *world = portageSettingsGetWorld(ps); + stringListPrint(world); printf("\n"); - - unsigned int len = stringListCount(strs); - //OverlayInfo *infos = calloc(len, sizeof(OverlayInfo)); - //int count = portageAPIGetAllInfos(l, strs, infos); - - OverlayInfo *oi = portageAPIGetAllInfo(l, "kuroo"); - if (oi) - { - printf("%s\n~~~~~~~~~~~~~~~~~~~~\n", oi->name); - printf("%s\n\n", oi->description); - overlayInfoFree(*oi); - free(oi); - } + stringListFree(world); - printf("\n"); + char *ak = portageSettingsAcceptKeywords(ps); + printf("ACCEPT_KEYWORDS=%s\n", ak); + free(ak); + + char *pd = portageSettingsPortdir(ps); + printf("PORTDIR=%s\n", pd); + free(pd); - //free(infos); - stringListFree(strs); + char *pdo = portageSettingsPortdirOverlay(ps); + printf("PORTDIR_OVERLAY=%s\n", pdo); + free(pdo); + + StringList *useflags = portageSettingsSystemUseFlags(ps); + stringListPrint(useflags); + printf("\n"); + stringListFree(useflags); - bareConfigFree(cfg); - portageAPIFree(l);*/ + portageSettingsFree(ps); portageFinalize(); |