diff options
author | 2010-07-31 23:11:07 +0200 | |
---|---|---|
committer | 2010-07-31 23:11:07 +0200 | |
commit | 9705260755becf5e24de6b365039f27d02d18806 (patch) | |
tree | 2103c63a19e59f1a2aecc2f2e74f619b151bb828 | |
parent | Fix calling get_allnodes instead of get_all_nodes (diff) | |
download | c-portage-9705260755becf5e24de6b365039f27d02d18806.tar.gz c-portage-9705260755becf5e24de6b365039f27d02d18806.tar.bz2 c-portage-9705260755becf5e24de6b365039f27d02d18806.zip |
Fix get_all_cpv_use, implement get_properties
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | Makefile.in | 15 | ||||
-rwxr-xr-x | libtool | 2 | ||||
-rw-r--r-- | src/dataconnect.c | 28 | ||||
-rw-r--r-- | src/dataconnect.h | 41 | ||||
-rw-r--r-- | src/flag.c | 4 | ||||
-rw-r--r-- | src/packageproperties.c | 52 | ||||
-rw-r--r-- | src/packageproperties.h | 17 | ||||
-rw-r--r-- | src/tester.c | 39 |
9 files changed, 165 insertions, 37 deletions
diff --git a/Makefile.am b/Makefile.am index d4d6895..f72a2e4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,11 +5,11 @@ lib_LTLIBRARIES = libportage.la #AM_CFLAGS = $(PYTHON_CFLAGS) --std=c99 -W -Wall -O0 -g -D_XOPEN_SOURCE=600 AM_CFLAGS = $(PYTHON_CFLAGS) --std=c99 -W -Wall -O0 -g -libportage_la_SOURCES = src/flag.c src/dataconnect.c src/portagesettings.c src/dict.c src/interpreter.c src/stringlist.c +libportage_la_SOURCES = src/packageproperties.c src/flag.c 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/flag.h src/dataconnect.h src/portagesettings.h src/portage.h src/dict.h src/interpreter.h src/stringlist.h +portage_include_HEADERS = src/packageproperties.h src/flag.h 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 55ab34b..b7e0ca1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -77,9 +77,9 @@ LTLIBRARIES = $(lib_LTLIBRARIES) am__DEPENDENCIES_1 = libportage_la_DEPENDENCIES = $(am__DEPENDENCIES_1) am__dirstamp = $(am__leading_dot)dirstamp -am_libportage_la_OBJECTS = src/flag.lo src/dataconnect.lo \ - src/portagesettings.lo src/dict.lo src/interpreter.lo \ - src/stringlist.lo +am_libportage_la_OBJECTS = src/packageproperties.lo src/flag.lo \ + 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 @@ -229,10 +229,10 @@ lib_LTLIBRARIES = libportage.la #AM_CFLAGS = $(PYTHON_CFLAGS) --std=c99 -W -Wall -O0 -g -D_XOPEN_SOURCE=600 AM_CFLAGS = $(PYTHON_CFLAGS) --std=c99 -W -Wall -O0 -g -libportage_la_SOURCES = src/flag.c src/dataconnect.c src/portagesettings.c src/dict.c src/interpreter.c src/stringlist.c +libportage_la_SOURCES = src/packageproperties.c src/flag.c 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/flag.h src/dataconnect.h src/portagesettings.h src/portage.h src/dict.h src/interpreter.h src/stringlist.h +portage_include_HEADERS = src/packageproperties.h src/flag.h src/dataconnect.h src/portagesettings.h src/portage.h src/dict.h src/interpreter.h src/stringlist.h all: all-am .SUFFIXES: @@ -310,6 +310,8 @@ src/$(am__dirstamp): src/$(DEPDIR)/$(am__dirstamp): @$(MKDIR_P) src/$(DEPDIR) @: > src/$(DEPDIR)/$(am__dirstamp) +src/packageproperties.lo: src/$(am__dirstamp) \ + src/$(DEPDIR)/$(am__dirstamp) src/flag.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/dataconnect.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/portagesettings.lo: src/$(am__dirstamp) \ @@ -330,6 +332,8 @@ mostlyclean-compile: -rm -f src/flag.lo -rm -f src/interpreter.$(OBJEXT) -rm -f src/interpreter.lo + -rm -f src/packageproperties.$(OBJEXT) + -rm -f src/packageproperties.lo -rm -f src/portagesettings.$(OBJEXT) -rm -f src/portagesettings.lo -rm -f src/stringlist.$(OBJEXT) @@ -342,6 +346,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dict.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/flag.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/interpreter.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/packageproperties.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@ @@ -86,7 +86,7 @@ NM="/usr/bin/nm -B" LN_S="ln -s" # What is the maximum length of a command? -max_cmd_len=3458764513820540925 +max_cmd_len=1572864 # Object file suffix (normally "o"). objext=o diff --git a/src/dataconnect.c b/src/dataconnect.c index 110e369..dc9d2ee 100644 --- a/src/dataconnect.c +++ b/src/dataconnect.c @@ -3,8 +3,8 @@ /** * Helper function to convert anytype of Python string (Unicode or not) into a C string. - * The object won't be DECREF'd but the returned char will be a copy of the data. - * The Python Object can then be safely DECREF'd. + * The object won't be DECREF'd but the returned char will be a copy of the data so it + * can then be safely DECREF'd after the call. */ static char* pyStringToString(PyObject *obj) { @@ -223,10 +223,26 @@ char* portageGetPackageSizeString(const char *pkg) return ret; } -//FIXME:str object is not callable. -//void portageGetProperties(const char*) -//{ -//} +PackageProperties* portageGetProperties(const char* pkg) +{ + assert(pkg); + PyObject *obj = executeFunction("portage.api.data_connect", "get_properties", "(z)", pkg); + if (!obj) + return NULL; + + PyObject *slot = PyObject_CallMethod(obj, "get_slot", NULL); + assert(slot); + PyObject *keywords = PyObject_CallMethod(obj, "get_keywords", NULL); + assert(keywords); + PyObject *flags = PyObject_CallMethod(obj, "get_flags", NULL); + assert(flags); + PyObject *homepages = PyObject_CallMethod(obj, "get_homepages", NULL); + assert(homepages); + + PackageProperties *ret = packagePropertiesCreate(pyStringToString(slot), listToCList(keywords), listToCList(flags), listToCList(homepages)); + + return ret; +} int portageIsOverlay(const char *pkg) { diff --git a/src/dataconnect.h b/src/dataconnect.h index cc990be..05d006a 100644 --- a/src/dataconnect.h +++ b/src/dataconnect.h @@ -2,30 +2,31 @@ #define DATACONNECT_H #include "stringlist.h" +#include "packageproperties.h" -StringList* portageGetVersions(const char*, int); -//int portageGetHardMasked(const char*); -StringList* portageGetInstalledFiles(const char*); +StringList* portageGetVersions(const char*, int); +//int portageGetHardMasked(const char*); +StringList* portageGetInstalledFiles(const char*); -char* portageBestVersion(StringList*); -char* portageGetBestEbuild(const char*); -char* portageGetDepEbuild(const char*); +char* portageBestVersion(StringList*); +char* portageGetBestEbuild(const char*); +char* portageGetDepEbuild(const char*); -StringList* portageGetMaskingStatus(const char*); -char* portageGetMaskingReason(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); +long int portageGetPackageSizeInt(const char*); +char* portageGetPackageSizeString(const char*); +PackageProperties* 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(); +StringList* portageGetResolvedPkgs(); +StringList* portageGetUnresolvedPkgs(); +StringList* portageGetAllNodes(); +StringList* portageGetInstalledList(); #endif @@ -122,8 +122,8 @@ int portageGetAllCpvUse(const char* pkg, StringList** use, StringList** use_expa assert(use_expand_hidden); assert(usemasked); assert(useforced); - - PyObject *obj = executeFunction("portage.api.flag", "get_installed_use", "(z)", pkg); + + PyObject *obj = executeFunction("portage.api.flag", "get_all_cpv_use", "(z)", pkg); if (!obj || !PySequence_Check(obj)) { *use = stringListCreate(0); diff --git a/src/packageproperties.c b/src/packageproperties.c new file mode 100644 index 0000000..7259f9d --- /dev/null +++ b/src/packageproperties.c @@ -0,0 +1,52 @@ +#include "stdlib.h" +#include "packageproperties.h" + +struct PackageProperties +{ + char* slot; + StringList* keywords; + StringList* flags; + StringList* homepages; +}; + +PackageProperties* packagePropertiesCreate(char *slot, StringList* keywords, StringList* flags, StringList *homepages) +{ + PackageProperties *ret = malloc(sizeof(PackageProperties)); + + ret->slot = slot; + ret->keywords = keywords; + ret->flags = flags; + ret->homepages = homepages; + + return ret; +} + +char* packagePropertiesGetSlot(PackageProperties *p) +{ + return p->slot; +} + +StringList* packagePropertiesGetKeywords(PackageProperties *p) +{ + return p->keywords; +} + +StringList* packagePropertiesGetFlags(PackageProperties *p) +{ + return p->flags; +} + +StringList* packagePropertiesGetHomepages(PackageProperties *p) +{ + return p->homepages; +} + +void packagePropertiesFree(PackageProperties *p) +{ + free(p->slot); + stringListFree(p->keywords); + stringListFree(p->flags); + stringListFree(p->homepages); + + free(p); +} diff --git a/src/packageproperties.h b/src/packageproperties.h new file mode 100644 index 0000000..d042753 --- /dev/null +++ b/src/packageproperties.h @@ -0,0 +1,17 @@ +#ifndef PACKAGE_PROPERTIES +#define PACKAGE_PROPERTIES + +#include "stringlist.h" + +typedef struct PackageProperties PackageProperties; + +PackageProperties* packagePropertiesCreate(char *slot, StringList* keywords, StringList* flags, StringList *homepages); + +char* packagePropertiesGetSlot(PackageProperties *p); +StringList* packagePropertiesGetKeywords(PackageProperties *p); +StringList* packagePropertiesGetFlags(PackageProperties *p); +StringList* packagePropertiesGetHomepages(PackageProperties *p); + +void packagePropertiesFree(PackageProperties *p); + +#endif diff --git a/src/tester.c b/src/tester.c index d9fbbc8..45ce798 100644 --- a/src/tester.c +++ b/src/tester.c @@ -1,5 +1,6 @@ #include <stdlib.h> #include <stdio.h> +#include <assert.h> #include "portage.h" @@ -44,10 +45,46 @@ int main(int argc, char *argv[]) free(oname); free(bp); - StringList *resolved = portageGetResolvedPkgs(); + /*StringList *resolved = portageGetResolvedPkgs(); stringListPrint(resolved); printf("\n"); stringListFree(resolved); + + StringList *unresolved = portageGetUnresolvedPkgs(); + stringListPrint(unresolved); + printf("\n"); + stringListFree(unresolved); + + StringList *installed = portageGetInstalledList(); + printf("Installed (%d) :\n", stringListCount(installed)); + stringListPrint(installed); + printf("\n"); + stringListFree(installed); + + StringList *all = portageGetAllNodes(); + printf("All Nodes (%d) :\n", stringListCount(all)); + stringListPrint(all); + printf("\n"); + stringListFree(all);*/ + + StringList *use = 1, *use_expand_hidden = 0, *usemasked = 0, *useforced = 0; + ret = portageGetAllCpvUse("kde-base/kdelibs-4.4.5", &use, &use_expand_hidden, &usemasked, &useforced); + if (!ret) + printf("ret was false, troubles ahead.\n"); + stringListPrint(use); + printf("\n"); + stringListFree(use); + stringListPrint(use_expand_hidden); + printf("\n"); + stringListFree(use_expand_hidden); + stringListPrint(usemasked); + printf("\n"); + stringListFree(usemasked); + stringListPrint(useforced); + printf("\n"); + stringListFree(useforced); + + portageFinalize(); |