]> git.ipfire.org Git - pakfire.git/commitdiff
Raise DependencyError from C module if request could not be solved
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Nov 2017 15:01:08 +0000 (16:01 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Nov 2017 15:05:40 +0000 (16:05 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/_pakfire/_pakfiremodule.c
src/_pakfire/errors.h [new file with mode: 0644]
src/_pakfire/request.c

index f67987d1766fe90cb06f63efc9b8664c56058054..7883980e536a5e33e3398c44d7806244393d93eb 100644 (file)
@@ -183,6 +183,7 @@ _pakfire_la_SOURCES = \
        src/_pakfire/capabilities.c \
        src/_pakfire/capabilities.h \
        src/_pakfire/constants.h \
+       src/_pakfire/errors.h \
        src/_pakfire/package.c \
        src/_pakfire/package.h \
        src/_pakfire/pool.c \
index 43d8b6f9920057777c6d876a80f75d2b04bdf85e..01900cf5930f4404439c190bab443f26f2f11fd8 100644 (file)
@@ -28,6 +28,7 @@
 #include "archive.h"
 #include "capabilities.h"
 #include "constants.h"
+#include "errors.h"
 #include "package.h"
 #include "pool.h"
 #include "problem.h"
@@ -117,6 +118,10 @@ PyMODINIT_FUNC PyInit__pakfire(void) {
        if (!module)
                return NULL;
 
+       PyExc_DependencyError = PyErr_NewException("_pakfire.DependencyError", NULL, NULL);
+       Py_INCREF(PyExc_DependencyError);
+       PyModule_AddObject(module, "DependencyError", PyExc_DependencyError);
+
        // Archive
        if (PyType_Ready(&ArchiveType) < 0)
                return NULL;
diff --git a/src/_pakfire/errors.h b/src/_pakfire/errors.h
new file mode 100644 (file)
index 0000000..4b26f7e
--- /dev/null
@@ -0,0 +1,29 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2017 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PYTHON_PAKFIRE_ERRORS_H
+#define PYTHON_PAKFIRE_ERRORS_H
+
+#include <Python.h>
+
+// Exceptions
+PyObject* PyExc_DependencyError;
+
+#endif /* PYTHON_PAKFIRE_ERRORS_H */
index 6d04d024ef2f8551736138bc352c5e583329452a..936cf798feb1437decfc3ac4fd78a27c42516ec0 100644 (file)
@@ -24,6 +24,7 @@
 #include <pakfire/errno.h>
 #include <pakfire/request.h>
 
+#include "errors.h"
 #include "package.h"
 #include "problem.h"
 #include "relation.h"
@@ -190,11 +191,35 @@ static PyObject* Request_distupgrade(RequestObject* self) {
        return Request_operation_return(ret);
 }
 
+static PyObject* Request_get_problems(RequestObject* self) {
+       PyObject* list = PyList_New(0);
+
+       PakfireProblem problem = pakfire_request_get_problems(self->request);
+       while (problem) {
+               PyObject* p = new_problem(problem);
+               PyList_Append(list, p);
+
+               Py_DECREF(p);
+
+               // Move on to next problem
+               problem = pakfire_problem_next(problem);
+       }
+
+       return list;
+}
+
 static PyObject* Request_solve(RequestObject* self) {
        int ret = pakfire_request_solve(self->request, 0);
 
-       if (ret)
-               Py_RETURN_NONE;
+       // Raise a DependencyError with all problems
+       // if the request could not be solved
+       if (ret) {
+               PyObject* problems = Request_get_problems(self);
+               PyErr_SetObject(PyExc_DependencyError, problems);
+
+               Py_DECREF(problems);
+               return NULL;
+       }
 
        // Allocate the transaction and return it
        PakfireTransaction transaction = pakfire_request_get_transaction(self->request);
@@ -210,23 +235,6 @@ static PyObject* Request_get_pool(RequestObject* self) {
        return (PyObject *)pool;
 }
 
-static PyObject* Request_get_problems(RequestObject* self) {
-       PyObject* list = PyList_New(0);
-
-       PakfireProblem problem = pakfire_request_get_problems(self->request);
-       while (problem) {
-               PyObject* p = new_problem(problem);
-               PyList_Append(list, p);
-
-               Py_DECREF(p);
-
-               // Move on to next problem
-               problem = pakfire_problem_next(problem);
-       }
-
-       return list;
-}
-
 static struct PyMethodDef Request_methods[] = {
        {
                "install",