]>
git.ipfire.org Git - people/stevee/pakfire.git/blob - python/src/solver.c
1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2011 Pakfire development team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
26 #include <solv/solverdebug.h>
28 PyTypeObject SolverType
= {
29 PyObject_HEAD_INIT(NULL
)
30 tp_name
: "_pakfire.Solver",
31 tp_basicsize
: sizeof(SolverObject
),
32 tp_flags
: Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
34 tp_dealloc
: (destructor
) Solver_dealloc
,
35 tp_doc
: "Sat Solver objects",
38 PyObject
* Solver_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
) {
43 if (!PyArg_ParseTuple(args
, "O", &pool
)) {
44 /* XXX raise exception */
47 self
= (SolverObject
*)type
->tp_alloc(type
, 0);
49 self
->_solver
= solver_create(pool
->_pool
);
50 if (self
->_solver
== NULL
) {
56 return (PyObject
*)self
;
59 PyObject
*Solver_dealloc(SolverObject
*self
) {
60 solver_free(self
->_solver
);
61 self
->ob_type
->tp_free((PyObject
*)self
);
66 PyObject
*Solver_get_fix_system(SolverObject
*self
, PyObject
*args
) {
67 return Py_BuildValue("i", self
->_solver
->fixsystem
);
70 PyObject
*Solver_set_fix_system(SolverObject
*self
, PyObject
*args
) {
73 if (!PyArg_ParseTuple(args
, "i", &val
)) {
74 /* XXX raise exception */
77 self
->_solver
->fixsystem
= val
;
82 PyObject
*Solver_get_allow_downgrade(SolverObject
*self
, PyObject
*args
) {
83 return Py_BuildValue("i", self
->_solver
->allowdowngrade
);
86 PyObject
*Solver_set_allow_downgrade(SolverObject
*self
, PyObject
*args
) {
89 if (!PyArg_ParseTuple(args
, "i", &val
)) {
90 /* XXX raise exception */
93 self
->_solver
->allowdowngrade
= val
;
98 PyObject
*Solver_get_allow_archchange(SolverObject
*self
, PyObject
*args
) {
99 return Py_BuildValue("i", self
->_solver
->allowarchchange
);
102 PyObject
*Solver_set_allow_archchange(SolverObject
*self
, PyObject
*args
) {
105 if (!PyArg_ParseTuple(args
, "i", &val
)) {
106 /* XXX raise exception */
109 self
->_solver
->allowarchchange
= val
;
114 PyObject
*Solver_get_allow_vendorchange(SolverObject
*self
, PyObject
*args
) {
115 return Py_BuildValue("i", self
->_solver
->allowvendorchange
);
118 PyObject
*Solver_set_allow_vendorchange(SolverObject
*self
, PyObject
*args
) {
121 if (!PyArg_ParseTuple(args
, "i", &val
)) {
122 /* XXX raise exception */
125 self
->_solver
->allowvendorchange
= val
;
130 PyObject
*Solver_get_allow_uninstall(SolverObject
*self
, PyObject
*args
) {
131 return Py_BuildValue("i", self
->_solver
->allowuninstall
);
134 PyObject
*Solver_set_allow_uninstall(SolverObject
*self
, PyObject
*args
) {
137 if (!PyArg_ParseTuple(args
, "i", &val
)) {
138 /* XXX raise exception */
141 self
->_solver
->allowuninstall
= val
;
146 PyObject
*Solver_get_updatesystem(SolverObject
*self
, PyObject
*args
) {
147 return Py_BuildValue("i", self
->_solver
->updatesystem
);
150 PyObject
*Solver_set_updatesystem(SolverObject
*self
, PyObject
*args
) {
153 if (!PyArg_ParseTuple(args
, "i", &val
)) {
154 /* XXX raise exception */
157 self
->_solver
->updatesystem
= val
;
162 PyObject
*Solver_get_do_split_provides(SolverObject
*self
, PyObject
*args
) {
163 return Py_BuildValue("i", self
->_solver
->dosplitprovides
);
166 PyObject
*Solver_set_do_split_provides(SolverObject
*self
, PyObject
*args
) {
169 if (!PyArg_ParseTuple(args
, "i", &val
)) {
170 /* XXX raise exception */
173 self
->_solver
->dosplitprovides
= val
;
178 PyObject
*Solver_solve(SolverObject
*self
, PyObject
*args
) {
179 RequestObject
*request
;
181 if (!PyArg_ParseTuple(args
, "O", &request
)) {
182 /* XXX raise exception */
185 // Make sure, the pool is prepared.
186 _Pool_prepare(self
->_solver
->pool
);
188 solver_solve(self
->_solver
, &request
->_queue
);
191 solver_printallsolutions(self
->_solver
);
194 if (self
->_solver
->problems
.count
== 0) {
201 PyObject
*Solver_get_problems(SolverObject
*self
, PyObject
*args
) {
202 RequestObject
*request
;
204 if (!PyArg_ParseTuple(args
, "O", &request
)) {
205 /* XXX raise exception */
209 PyObject
*list
= PyList_New(0);
211 ProblemObject
*problem
;
213 while ((p
= solver_next_problem(self
->_solver
, p
)) != 0) {
214 problem
= PyObject_New(ProblemObject
, &ProblemType
);
216 problem
->_pool
= self
->_solver
->pool
;
217 problem
->_solver
= self
->_solver
;
219 Problem_init(problem
);
221 PyList_Append(list
, (PyObject
*)problem
);