From: Michael Tremer Date: Thu, 2 Nov 2017 15:01:08 +0000 (+0100) Subject: Raise DependencyError from C module if request could not be solved X-Git-Tag: 0.9.28~1285^2~1327 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5845b60f50c4fff78901e3d71bb3afbdbaaccdb;p=pakfire.git Raise DependencyError from C module if request could not be solved Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index f67987d17..7883980e5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/_pakfire/_pakfiremodule.c b/src/_pakfire/_pakfiremodule.c index 43d8b6f99..01900cf59 100644 --- a/src/_pakfire/_pakfiremodule.c +++ b/src/_pakfire/_pakfiremodule.c @@ -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 index 000000000..4b26f7efc --- /dev/null +++ b/src/_pakfire/errors.h @@ -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 . # +# # +#############################################################################*/ + +#ifndef PYTHON_PAKFIRE_ERRORS_H +#define PYTHON_PAKFIRE_ERRORS_H + +#include + +// Exceptions +PyObject* PyExc_DependencyError; + +#endif /* PYTHON_PAKFIRE_ERRORS_H */ diff --git a/src/_pakfire/request.c b/src/_pakfire/request.c index 6d04d024e..936cf798f 100644 --- a/src/_pakfire/request.c +++ b/src/_pakfire/request.c @@ -24,6 +24,7 @@ #include #include +#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",