aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/dataconnect.c')
-rw-r--r--src/dataconnect.c375
1 files changed, 375 insertions, 0 deletions
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;
+}