From: Michael Tremer Date: Tue, 29 Aug 2023 16:47:57 +0000 (+0000) Subject: packages: Export build architectures in Python X-Git-Tag: 0.9.29~54 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=52d219514eb08761382385dfcdb6f35877863cf1;p=pakfire.git packages: Export build architectures in Python Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/package.c b/src/_pakfire/package.c index 0cc17b324..153b253d4 100644 --- a/src/_pakfire/package.c +++ b/src/_pakfire/package.c @@ -359,6 +359,29 @@ static PyObject* Package_get_size(PackageObject* self) { return PyLong_FromUnsignedLongLong(size); } +static PyObject* Package_get_build_arches(PackageObject* self) { + PyObject* ret = NULL; + + // Fetch all supported arches + char** build_arches = pakfire_package_get_strings(self->package, PAKFIRE_PKG_BUILD_ARCHES); + if (!build_arches) { + ret = PyList_New(0); + goto END; + } + + // Make a new list + ret = PyUnicodeList_FromStringArray(build_arches); + + // Cleanup + for (char** build_arch = build_arches; *build_arch; build_arch++) { + free(*build_arch); + } + free(build_arches); + +END: + return ret; +} + static PyObject* Package_get_buildhost(PackageObject* self) { const char* build_host = pakfire_package_get_string(self->package, PAKFIRE_PKG_BUILD_HOST); if (!build_host) @@ -905,6 +928,13 @@ static struct PyGetSetDef Package_getsetters[] = { NULL, NULL }, + { + "build_arches", + (getter)Package_get_build_arches, + NULL, + NULL, + NULL, + }, { "source_package", (getter)Package_get_source_package, diff --git a/src/_pakfire/util.c b/src/_pakfire/util.c index fb2b1f133..085ddcdd4 100644 --- a/src/_pakfire/util.c +++ b/src/_pakfire/util.c @@ -33,6 +33,36 @@ #include "package.h" #include "util.h" +PyObject* PyUnicodeList_FromStringArray(char** l) { + PyObject* list = NULL; + PyObject* s = NULL; + int r; + + // Check inputs + if (!l) + return NULL; + + list = PyList_New(0); + if (!list) + goto ERROR; + + while (*l) { + s = PyUnicode_FromString(*l); + if (!s) + goto ERROR; + + r = PyList_Append(list, s); + if (r) + goto ERROR; + } + +ERROR: + if (list) + Py_DECREF(list); + + return NULL; +} + PyObject* PyList_FromPackageList(struct pakfire_packagelist* packagelist) { PyObject* list = PyList_New(0); diff --git a/src/_pakfire/util.h b/src/_pakfire/util.h index adf9f651f..343ec0eb3 100644 --- a/src/_pakfire/util.h +++ b/src/_pakfire/util.h @@ -27,6 +27,8 @@ #include #include +PyObject* PyUnicodeList_FromStringArray(char** l); + PyObject* PyList_FromPackageList(struct pakfire_packagelist* packagelist); PyObject* PyList_FromFileList(struct pakfire_filelist* filelist); diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 6a75f063f..c2d1967fe 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -179,6 +179,7 @@ global: pakfire_package_get_reverse_requires; pakfire_package_get_size; pakfire_package_get_string; + pakfire_package_get_strings; pakfire_package_get_uuid; pakfire_package_id; pakfire_package_installcheck; @@ -188,6 +189,7 @@ global: pakfire_package_set_num; pakfire_package_set_path; pakfire_package_set_string; + pakfire_package_set_strings; pakfire_package_set_uuid; pakfire_package_unref; diff --git a/tests/python/package.py b/tests/python/package.py index 723a5fed8..e6a433a73 100755 --- a/tests/python/package.py +++ b/tests/python/package.py @@ -83,6 +83,8 @@ class Test(unittest.TestCase): self.assertEqual(p.source_arch, "src") self.assertEqual(p.source_evr, "1.3-2.ipfire3") + self.assertEqual(p.build_arches, []) + # Digest algo, digest = p.digest