]> git.ipfire.org Git - pakfire.git/commitdiff
python: transaction: Add function to run the transaction
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Mar 2025 17:59:02 +0000 (17:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Mar 2025 17:59:02 +0000 (17:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/transaction.c

index 8dfb7af69d25ad1425a3027af85081403c5b2c2a..a56bd04e28754eac62f6fdd4936ab9cba9626812 100644 (file)
@@ -161,6 +161,36 @@ ERROR:
        return NULL;
 }
 
+static PyObject* Transaction_run(TransactionObject* self) {
+       char* problems = NULL;
+       int r;
+
+       // Run the transaction
+       r = pakfire_transaction_run(self->transaction);
+       if (r < 0) {
+               errno = -r;
+               PyErr_SetFromErrno(PyExc_OSError);
+               goto ERROR;
+
+       // Solving failed :(
+       } else if (r > 0) {
+               PyErr_SetString(PyExc_DependencyError, problems);
+               goto ERROR;
+       }
+
+       // Problems should never be set here
+       assert(problems == NULL);
+
+       // Return None if everything was okay
+       Py_RETURN_NONE;
+
+ERROR:
+       if (problems)
+               free(problems);
+
+       return NULL;
+}
+
 static struct PyMethodDef Transaction_methods[] = {
        {
                "install",
@@ -174,6 +204,12 @@ static struct PyMethodDef Transaction_methods[] = {
                METH_VARARGS|METH_KEYWORDS,
                NULL,
        },
+       {
+               "run",
+               (PyCFunction)Transaction_run,
+               METH_NOARGS,
+               NULL,
+       },
        {
                "solve",
                (PyCFunction)Transaction_solve,