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 /* enable splitprovides by default */
57 solver_set_flag(self
->_solver
, SOLVER_FLAG_SPLITPROVIDES
, 1);
59 /* keep explicit obsoletes */
60 solver_set_flag(self
->_solver
, SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES
, 1);
62 return (PyObject
*)self
;
65 PyObject
*Solver_dealloc(SolverObject
*self
) {
66 solver_free(self
->_solver
);
67 self
->ob_type
->tp_free((PyObject
*)self
);
72 PyObject
*Solver_get_flag(SolverObject
*self
, PyObject
*args
) {
75 if (!PyArg_ParseTuple(args
, "i", &flag
)) {
79 int val
= solver_get_flag(self
->_solver
, flag
);
80 return Py_BuildValue("i", val
);
83 PyObject
*Solver_set_flag(SolverObject
*self
, PyObject
*args
) {
84 int flag
= 0, val
= 0;
86 if (!PyArg_ParseTuple(args
, "ii", &flag
, &val
)) {
90 solver_set_flag(self
->_solver
, flag
, val
);
94 PyObject
*Solver_get_allow_downgrade(SolverObject
*self
, PyObject
*args
) {
95 int val
= solver_get_flag(self
->_solver
, SOLVER_FLAG_ALLOW_DOWNGRADE
);
97 return Py_BuildValue("i", val
);
100 PyObject
*Solver_set_allow_downgrade(SolverObject
*self
, PyObject
*args
) {
103 if (!PyArg_ParseTuple(args
, "i", &val
)) {
107 solver_set_flag(self
->_solver
, SOLVER_FLAG_ALLOW_DOWNGRADE
, val
);
111 PyObject
*Solver_get_allow_archchange(SolverObject
*self
, PyObject
*args
) {
112 int val
= solver_get_flag(self
->_solver
, SOLVER_FLAG_ALLOW_ARCHCHANGE
);
114 return Py_BuildValue("i", val
);
117 PyObject
*Solver_set_allow_archchange(SolverObject
*self
, PyObject
*args
) {
120 if (!PyArg_ParseTuple(args
, "i", &val
)) {
124 solver_set_flag(self
->_solver
, SOLVER_FLAG_ALLOW_ARCHCHANGE
, val
);
128 PyObject
*Solver_get_allow_vendorchange(SolverObject
*self
, PyObject
*args
) {
129 int val
= solver_get_flag(self
->_solver
, SOLVER_FLAG_ALLOW_VENDORCHANGE
);
131 return Py_BuildValue("i", val
);
134 PyObject
*Solver_set_allow_vendorchange(SolverObject
*self
, PyObject
*args
) {
137 if (!PyArg_ParseTuple(args
, "i", &val
)) {
141 solver_set_flag(self
->_solver
, SOLVER_FLAG_ALLOW_VENDORCHANGE
, val
);
145 PyObject
*Solver_get_allow_uninstall(SolverObject
*self
, PyObject
*args
) {
146 int val
= solver_get_flag(self
->_solver
, SOLVER_FLAG_ALLOW_UNINSTALL
);
148 return Py_BuildValue("i", val
);
151 PyObject
*Solver_set_allow_uninstall(SolverObject
*self
, PyObject
*args
) {
154 if (!PyArg_ParseTuple(args
, "i", &val
)) {
158 solver_set_flag(self
->_solver
, SOLVER_FLAG_ALLOW_UNINSTALL
, val
);
162 PyObject
*Solver_get_updatesystem(SolverObject
*self
, PyObject
*args
) {
163 //return Py_BuildValue("i", self->_solver->updatesystem);
167 PyObject
*Solver_set_updatesystem(SolverObject
*self
, PyObject
*args
) {
170 if (!PyArg_ParseTuple(args, "i", &val)) {
174 self->_solver->updatesystem = val; */
179 PyObject
*Solver_get_do_split_provides(SolverObject
*self
, PyObject
*args
) {
180 int val
= solver_get_flag(self
->_solver
, SOLVER_FLAG_SPLITPROVIDES
);
182 return Py_BuildValue("i", val
);
185 PyObject
*Solver_set_do_split_provides(SolverObject
*self
, PyObject
*args
) {
188 if (!PyArg_ParseTuple(args
, "i", &val
)) {
192 solver_set_flag(self
->_solver
, SOLVER_FLAG_SPLITPROVIDES
, val
);
196 PyObject
*Solver_solve(SolverObject
*self
, PyObject
*args
) {
197 RequestObject
*request
;
201 if (!PyArg_ParseTuple(args
, "O|i", &request
, &force_best
)) {
205 // Make sure, the pool is prepared.
206 _Pool_prepare(self
->_solver
->pool
);
208 /* Force best solution. */
210 for (int i
= 0; i
< request
->_queue
.count
; i
+= 2)
211 request
->_queue
.elements
[i
] |= SOLVER_FORCEBEST
;
214 res
= solver_solve(self
->_solver
, &request
->_queue
);
217 solver_printallsolutions(self
->_solver
);
226 PyObject
*Solver_get_problems(SolverObject
*self
, PyObject
*args
) {
227 RequestObject
*request
;
229 if (!PyArg_ParseTuple(args
, "O", &request
)) {
233 PyObject
*list
= PyList_New(0);
235 ProblemObject
*problem
;
237 while ((p
= solver_next_problem(self
->_solver
, p
)) != 0) {
238 problem
= PyObject_New(ProblemObject
, &ProblemType
);
240 problem
->_pool
= self
->_solver
->pool
;
241 problem
->_solver
= self
->_solver
;
243 Problem_init(problem
);
245 PyList_Append(list
, (PyObject
*)problem
);