aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dataconnect.c28
-rw-r--r--src/dataconnect.h41
-rw-r--r--src/flag.c4
-rw-r--r--src/packageproperties.c52
-rw-r--r--src/packageproperties.h17
-rw-r--r--src/tester.c39
6 files changed, 152 insertions, 29 deletions
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
diff --git a/src/flag.c b/src/flag.c
index dc50afb..b9e7981 100644
--- a/src/flag.c
+++ b/src/flag.c
@@ -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();