]> git.ipfire.org Git - pakfire.git/commitdiff
python: Remove build/mkimage/shell from the Pakfire object
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 5 Oct 2024 14:35:50 +0000 (14:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 5 Oct 2024 14:35:50 +0000 (14:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c

index b82f28a54250ce2aa4593077b253c7062714b938..4a387b64eb448a0cf38af7bf1b6feee4db266582 100644 (file)
@@ -170,74 +170,6 @@ static PyObject* Pakfire_get_repo(PakfireObject* self, PyObject* args) {
        return obj;
 }
 
-static int convert_packages(PyObject* object, void* address) {
-       char*** packages = (char***)address;
-
-       // Called for cleanup
-       if (!object)
-               goto ERROR;
-
-       // Nothing to do when object is None
-       if (object == Py_None)
-               return Py_CLEANUP_SUPPORTED;
-
-       if (!PySequence_Check(object)) {
-               PyErr_SetString(PyExc_ValueError, "Packages must be a sequence");
-               goto ERROR;
-       }
-
-       const unsigned int length = PySequence_Length(object);
-       if (!length)
-               return Py_CLEANUP_SUPPORTED;
-
-       // Allocate array
-       *packages = calloc(length + 1, sizeof(*packages));
-       if (!*packages) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               goto ERROR;
-       }
-
-       for (unsigned int i = 0; i < length; i++) {
-               PyObject* item = PySequence_GetItem(object, i);
-
-               // Check if input is a string
-               if (!PyUnicode_Check(item)) {
-                       Py_DECREF(item);
-
-                       PyErr_SetString(PyExc_AttributeError, "Expected a string");
-                       goto ERROR;
-               }
-
-               // Fetch string
-               const char* package = PyUnicode_AsUTF8(item);
-               if (!package) {
-                       Py_DECREF(item);
-                       goto ERROR;
-               }
-
-               // Add package to array
-               (*packages)[i] = strdup(package);
-               if (!(*packages)[i]) {
-                       Py_DECREF(item);
-                       goto ERROR;
-               }
-
-               Py_DECREF(item);
-       }
-
-       // Success
-       return Py_CLEANUP_SUPPORTED;
-
-ERROR:
-       if (*packages) {
-               for (char** package = *packages; *package; package++)
-                       free(*package);
-               free(*packages);
-       }
-
-       return 0;
-}
-
 /*
        XXX This could be moved out of here as this no longer depends on Pakfire
 */
@@ -700,159 +632,6 @@ ERROR:
        return list;
 }
 
-static PyObject* execute_return_value(int r) {
-       // Raise an OS error if r < 0
-       if (r < 0) {
-               errno = -r;
-
-               PyErr_SetFromErrno(PyExc_OSError);
-               return NULL;
-
-       // Raise exception when the command failed
-       } else if (r > 0) {
-               PyObject* code = PyLong_FromLong(r);
-
-               PyErr_SetObject(PyExc_CommandExecutionError, code);
-               Py_DECREF(code);
-
-               return NULL;
-       }
-
-       Py_RETURN_NONE;
-}
-
-static PyObject* Pakfire_build(PakfireObject* self, PyObject* args, PyObject* kwargs) {
-       char* kwlist[] = {
-               "path",
-               "target",
-               "build_id",
-               "ccache_path",
-               "interactive",
-               "disable_snapshot",
-               "disable_ccache",
-               "disable_tests",
-               NULL,
-       };
-       struct pakfire_build* build = NULL;
-       const char* path = NULL;
-       const char* target = NULL;
-       const char* build_id = NULL;
-       const char* ccache_path = NULL;
-       int interactive = 0;
-       int disable_snapshot = 0;
-       int disable_ccache = 0;
-       int disable_tests = 0;
-       int r;
-
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zzzpppp", kwlist,
-                       &path, &target, &build_id, &ccache_path, &interactive,
-                       &disable_snapshot, &disable_ccache, &disable_tests))
-               return NULL;
-
-       int flags = 0;
-
-       if (interactive)
-               flags |= PAKFIRE_BUILD_INTERACTIVE;
-
-       // Disable snapshot if requested
-       if (disable_snapshot)
-               flags |= PAKFIRE_BUILD_DISABLE_SNAPSHOT;
-
-       // Disable ccache if requested
-       if (disable_ccache)
-               flags |= PAKFIRE_BUILD_DISABLE_CCACHE;
-
-       // Disable tests if requested
-       if (disable_tests)
-               flags |= PAKFIRE_BUILD_DISABLE_TESTS;
-
-       // Create a new build environment
-       r = pakfire_build_create(&build, self->pakfire, build_id, flags);
-       if (r) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               goto ERROR;
-       }
-
-       // Set target
-       if (target) {
-               r = pakfire_build_set_target(build, target);
-               if (r) {
-                       PyErr_SetFromErrno(PyExc_OSError);
-                       goto ERROR;
-               }
-       }
-
-       // Set ccache path
-       if (ccache_path) {
-               r = pakfire_build_set_ccache_path(build, ccache_path);
-               if (r) {
-                       PyErr_SetFromErrno(PyExc_OSError);
-                       goto ERROR;
-               }
-       }
-
-       Py_BEGIN_ALLOW_THREADS
-
-       // Run build
-       r = pakfire_build_exec(build, path);
-       if (r) {
-               Py_BLOCK_THREADS;
-
-               if (r < 0) {
-                       PyErr_SetFromErrno(PyExc_OSError);
-
-               // Raise a command execution error
-               } else {
-                       PyObject* code = PyLong_FromLong(r);
-
-                       PyErr_SetObject(PyExc_CommandExecutionError, code);
-                       Py_DECREF(code);
-               }
-
-               goto ERROR;
-       }
-
-       Py_END_ALLOW_THREADS
-
-ERROR:
-       if (build)
-               pakfire_build_unref(build);
-
-       if (r)
-               return NULL;
-
-       Py_RETURN_NONE;
-}
-
-static PyObject* Pakfire_shell(PakfireObject* self, PyObject* args, PyObject* kwargs) {
-       char* kwlist[] = {
-               "install",
-               "disable_snapshot",
-               NULL,
-       };
-       char** packages = NULL;
-       int disable_snapshot = 0;
-       int r;
-
-       // Parse everything
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&p", kwlist,
-                       convert_packages, &packages, &disable_snapshot))
-               return NULL;
-
-       int flags = 0;
-
-       if (disable_snapshot)
-               flags |= PAKFIRE_BUILD_DISABLE_SNAPSHOT;
-
-       Py_BEGIN_ALLOW_THREADS
-
-       r = pakfire_shell(self->pakfire, (const char**)packages, flags);
-
-       Py_END_ALLOW_THREADS
-
-       return execute_return_value(r);
-}
-
 static PyObject* Pakfire_clean(PakfireObject* self) {
        int r;
 
@@ -986,66 +765,7 @@ ERROR:
        return ret;
 }
 
-static PyObject* Pakfire_mkimage(PakfireObject* self, PyObject* args, PyObject* kwargs) {
-       char* kwlist[] = {
-               "type",
-               "path",
-               NULL,
-       };
-       struct pakfire_build* build = NULL;
-       const char* type = NULL;
-       PyObject* file = NULL;
-       FILE* f = NULL;
-       int r;
-
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO", kwlist, &type, &file))
-               return NULL;
-
-       // Make a file handle out of file
-       f = PyObject_AsFileHandle(file, "w");
-       if (!f)
-               return NULL;
-
-       // Create a new build environment
-       r = pakfire_build_create(&build, self->pakfire, NULL, 0);
-       if (r) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               goto ERROR;
-       }
-
-       Py_BEGIN_ALLOW_THREADS
-
-       // Run mkimage
-       r = pakfire_build_mkimage(build, type, f);
-       if (r) {
-               Py_BLOCK_THREADS;
-
-               if (r < 0)
-                       PyErr_SetFromErrno(PyExc_OSError);
-
-               goto ERROR;
-       }
-
-       Py_END_ALLOW_THREADS
-
-ERROR:
-       if (build)
-               pakfire_build_unref(build);
-       if (f)
-               fclose(f);
-       if (r)
-               return NULL;
-
-       Py_RETURN_NONE;
-}
-
 static struct PyMethodDef Pakfire_methods[] = {
-       {
-               "build",
-               (PyCFunction)Pakfire_build,
-               METH_VARARGS|METH_KEYWORDS,
-               NULL
-       },
        {
                "clean",
                (PyCFunction)Pakfire_clean,
@@ -1082,12 +802,6 @@ static struct PyMethodDef Pakfire_methods[] = {
                METH_VARARGS,
                NULL,
        },
-       {
-               "mkimage",
-               (PyCFunction)Pakfire_mkimage,
-               METH_VARARGS|METH_KEYWORDS,
-               NULL
-       },
        {
                "open",
                (PyCFunction)Pakfire_open,
@@ -1112,12 +826,6 @@ static struct PyMethodDef Pakfire_methods[] = {
                METH_VARARGS|METH_KEYWORDS,
                NULL
        },
-       {
-               "shell",
-               (PyCFunction)Pakfire_shell,
-               METH_VARARGS|METH_KEYWORDS,
-               NULL,
-       },
        {
                "version_compare",
                (PyCFunction)Pakfire_version_compare,