From 0e76a31c866aef80cf7c5f04e54bef3e3150a761 Mon Sep 17 00:00:00 2001 From: Detlev Casanova Date: Sun, 1 Aug 2010 16:47:01 +0200 Subject: Implement get_hard_masked and get_path, Fix right method calls, Add a contains function to StringList, Make the test application look like emerge : ./run-test porthole Gives the best version to install with it's use flags. --- src/dataconnect.c | 95 +++++++++++++++++++++++++++---------------------------- 1 file changed, 46 insertions(+), 49 deletions(-) (limited to 'src/dataconnect.c') diff --git a/src/dataconnect.c b/src/dataconnect.c index dc9d2ee..6c2764d 100644 --- a/src/dataconnect.c +++ b/src/dataconnect.c @@ -53,9 +53,32 @@ StringList* portageGetVersions(const char *pkg, int include_masked) return ret; } -//int portageGetHardMasked(const char*) -//{ -//} +int portageGetHardMasked(const char* pkg, StringList** no_check, StringList** check) +{ + PyObject *obj = executeFunction("portage.api.data_connect", "get_hard_masked", "(z)", pkg); + if (!obj || !PySequence_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return 0; + } + + PyObject *pynocheck = PySequence_GetItem(obj, 0); + assert(pynocheck); + PyObject *pycheck = PySequence_GetItem(obj, 1); + assert(pycheck); + + *no_check = listToCList(pynocheck); + *check = listToCList(pycheck); + + Py_DECREF(pynocheck); + Py_DECREF(pycheck); + Py_DECREF(obj); + + return 1; +} StringList* portageGetInstalledFiles(const char *pkg) { @@ -81,16 +104,10 @@ char* portageBestVersion(StringList *pkgs) { assert(pkgs); PyObject *pylist = cListToPyList(pkgs); - PyObject *obj = executeFunction("portage.api.data_connect", "best_version", "(O)", pylist); + PyObject *obj = executeFunction("portage.api.data_connect", "best", "(O)", pylist); Py_DECREF(pylist); - if (!obj || !PyString_Check(obj)) - { - if (obj) - { - Py_DECREF(obj); - } + if (!obj) return NULL; - } char *ret = pyStringToString(obj); @@ -124,14 +141,8 @@ 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); - } + if (!obj) return NULL; - } char *ret = pyStringToString(obj); @@ -166,14 +177,8 @@ 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); - } + if (!obj) return NULL; - } char *ret = pyStringToString(obj); @@ -207,14 +212,8 @@ 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); - } + if (!obj) return NULL; - } char *ret = pyStringToString(obj); @@ -262,14 +261,8 @@ 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); - } + if (!obj) return NULL; - } char *ret = pyStringToString(obj); @@ -305,14 +298,8 @@ char* portageGetOverlayNameFromPkg(const char *pkg) 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); - } + if (!obj) return NULL; - } char *ret = pyStringToString(obj); @@ -321,9 +308,19 @@ char* portageGetOverlayNameFromPkg(const char *pkg) return ret; } -//char* portageGetPath(const char*, int) -//{ -//} +char* portageGetPath(const char* pkg, int vardb) +{ + assert(pkg); + PyObject *obj = executeFunction("portage.api.data_connect", "get_path", "(zI)", pkg, vardb); + if (!obj) + return NULL; + + char *ret = pyStringToString(obj); + + Py_DECREF(obj); + + return ret; +} StringList* portageGetResolvedPkgs() -- cgit v1.2.3-65-gdbad