From: Michael Tremer Date: Mon, 27 Jan 2025 15:41:20 +0000 (+0000) Subject: python: Take configuration as string and fix return values X-Git-Tag: 0.9.30~353 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=abbc415e4f36fddc0db46a7685aa9781da5fb770;p=pakfire.git python: Take configuration as string and fix return values Signed-off-by: Michael Tremer --- diff --git a/src/python/pakfire.c b/src/python/pakfire.c index 0c04a31b..007a1c08 100644 --- a/src/python/pakfire.c +++ b/src/python/pakfire.c @@ -59,19 +59,17 @@ static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds) } static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { + const char* kwlist[] = { "ctx", "path", "arch", "config", NULL }; struct pakfire_config* c = NULL; - const char* kwlist[] = { "ctx", "path", "arch", "conf", NULL }; - CtxObject* ctx = NULL; + const char* config = NULL; const char* path = NULL; const char* arch = NULL; - PyObject* conf = Py_None; - int r = 1; + CtxObject* ctx = NULL; + int r; - FILE* f = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|zzO", (char**)kwlist, - &CtxType, &ctx, &path, &arch, &conf)) - goto ERROR; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|zzz", (char**)kwlist, + &CtxType, &ctx, &path, &arch, &config)) + return -1; // Create a new configuration object r = pakfire_config_create(&c); @@ -80,29 +78,24 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { goto ERROR; } - // Map the configuration - if (conf != Py_None) { - f = PyObject_AsFileHandle(conf, "r"); - if (!f) - goto ERROR; - - // Read the configuration - r = pakfire_config_read(c, f); + // Parse the configuration + if (config) { + r = pakfire_config_parse(c, config, -1); if (r < 0) { + errno = -r; + PyErr_SetFromErrno(PyExc_OSError); goto ERROR; } } - int flags = 0; - Py_BEGIN_ALLOW_THREADS // Store a reference to the context self->ctx = pakfire_ctx_ref(ctx->ctx); // Create a new Pakfire instance - r = pakfire_create(&self->pakfire, self->ctx, c, path, arch, flags); + r = pakfire_create(&self->pakfire, self->ctx, c, path, arch, 0); Py_END_ALLOW_THREADS @@ -113,24 +106,20 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { // Invalid architecture or path case EINVAL: PyErr_SetString(PyExc_ValueError, "Invalid architecture or path"); - break; + goto ERROR; // Anything else default: PyErr_SetFromErrno(PyExc_OSError); + goto ERROR; } - - r = -1; - goto ERROR; } ERROR: if (c) pakfire_config_unref(c); - if (f) - fclose(f); - return -r; + return r; } static void Pakfire_dealloc(PakfireObject* self) {