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 #############################################################################*/
31 PyTypeObject ProblemType
= {
32 PyObject_HEAD_INIT(NULL
)
33 tp_name
: "_pakfire.Problem",
34 tp_basicsize
: sizeof(ProblemObject
),
35 tp_flags
: Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
37 tp_dealloc
: (destructor
) Problem_dealloc
,
38 tp_doc
: "Sat Problem objects",
39 tp_str
: (reprfunc
)Problem_string
,
42 PyObject
* Problem_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
) {
45 RequestObject
*request
;
48 if (!PyArg_ParseTuple(args
, "OOi", &solver
, &request
, &problem_id
)) {
49 /* XXX raise exception */
53 self
= (ProblemObject
*)type
->tp_alloc(type
, 0);
55 self
->_pool
= request
->_pool
;
56 self
->_solver
= solver
->_solver
;
57 self
->_id
= problem_id
;
59 // Initialize problem information.
63 return (PyObject
*)self
;
66 PyObject
*Problem_dealloc(ProblemObject
*self
) {
67 self
->ob_type
->tp_free((PyObject
*)self
);
72 PyObject
*Problem_init(ProblemObject
*self
) {
73 Id id
= solver_findproblemrule(self
->_solver
, self
->_id
);
75 self
->rule
= solver_ruleinfo(self
->_solver
, id
, &self
->source
,
76 &self
->target
, &self
->dep
);
81 PyObject
*Problem_get_rule(ProblemObject
*self
) {
82 return Py_BuildValue("i", self
->rule
);
85 PyObject
*Problem_get_source(ProblemObject
*self
) {
86 SolvableObject
*solvable
;
88 if (self
->source
== ID_NULL
)
91 solvable
= PyObject_New(SolvableObject
, &SolvableType
);
95 solvable
->_pool
= self
->_pool
;
96 solvable
->_id
= self
->source
;
98 return (PyObject
*)solvable
;
101 PyObject
*Problem_get_target(ProblemObject
*self
) {
102 SolvableObject
*solvable
;
104 if (self
->target
== ID_NULL
)
107 solvable
= PyObject_New(SolvableObject
, &SolvableType
);
108 if (solvable
== NULL
)
111 solvable
->_pool
= self
->_pool
;
112 solvable
->_id
= self
->target
;
114 return (PyObject
*)solvable
;
117 PyObject
*Problem_get_dep(ProblemObject
*self
) {
118 RelationObject
*relation
;
120 if (self
->dep
== ID_NULL
)
123 relation
= PyObject_New(RelationObject
, &RelationType
);
124 if (relation
== NULL
)
127 relation
->_pool
= self
->_pool
;
128 relation
->_id
= self
->dep
;
130 return (PyObject
*)relation
;
133 PyObject
*Problem_get_solutions(ProblemObject
*self
) {
134 SolutionObject
*solution
;
137 PyObject
*list
= PyList_New(0);
139 while ((s
= solver_next_solution(self
->_solver
, self
->_id
, s
)) != 0) {
140 solution
= PyObject_New(SolutionObject
, &SolutionType
);
142 solution
->_solver
= self
->_solver
;
143 solution
->problem_id
= self
->_id
;
146 PyList_Append(list
, (PyObject
*)solution
);
152 PyObject
*Problem_string(ProblemObject
*self
) {
153 Pool
*pool
= self
->_pool
;
156 switch (self
->rule
) {
157 case SOLVER_RULE_DISTUPGRADE
:
158 snprintf(s
, STRING_SIZE
- 1,
159 _("%s does not belong to a distupgrade repository"),
160 pool_solvid2str(pool
, self
->source
)
164 case SOLVER_RULE_INFARCH
:
165 snprintf(s
, STRING_SIZE
- 1,
166 _("%s has inferior architecture"),
167 pool_solvid2str(pool
, self
->source
)
171 case SOLVER_RULE_UPDATE
:
172 snprintf(s
, STRING_SIZE
- 1,
173 _("problem with installed package %s"),
174 pool_solvid2str(pool
, self
->source
)
178 case SOLVER_RULE_JOB
:
179 snprintf(s
, STRING_SIZE
- 1, _("conflicting requests"));
182 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP
:
183 snprintf(s
, STRING_SIZE
- 1,
184 _("nothing provides requested %s"),
185 pool_dep2str(pool
, self
->dep
)
189 case SOLVER_RULE_RPM
:
190 snprintf(s
, STRING_SIZE
- 1, _("some dependency problem"));
193 case SOLVER_RULE_RPM_NOT_INSTALLABLE
:
194 snprintf(s
, STRING_SIZE
- 1,
195 _("package %s is not installable"),
196 pool_solvid2str(pool
, self
->source
)
200 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP
:
201 snprintf(s
, STRING_SIZE
- 1,
202 _("nothing provides %s needed by %s"),
203 pool_dep2str(pool
, self
->dep
), pool_solvid2str(pool
, self
->source
)
207 case SOLVER_RULE_RPM_SAME_NAME
:
208 snprintf(s
, STRING_SIZE
- 1,
209 _("cannot install both %s and %s"),
210 pool_solvid2str(pool
, self
->source
), pool_solvid2str(pool
, self
->target
)
214 case SOLVER_RULE_RPM_PACKAGE_CONFLICT
:
215 snprintf(s
, STRING_SIZE
- 1,
216 _("package %s conflicts with %s provided by %s"),
217 pool_solvid2str(pool
, self
->source
), pool_dep2str(pool
, self
->dep
),
218 pool_solvid2str(pool
, self
->target
)
222 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES
:
223 snprintf(s
, STRING_SIZE
- 1,
224 _("package %s obsoletes %s provided by %s"),
225 pool_solvid2str(pool
, self
->source
), pool_dep2str(pool
, self
->dep
),
226 pool_solvid2str(pool
, self
->target
)
230 case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES
:
231 snprintf(s
, STRING_SIZE
- 1,
232 _("installed package %s obsoletes %s provided by %s"),
233 pool_solvid2str(pool
, self
->source
), pool_dep2str(pool
, self
->dep
),
234 pool_solvid2str(pool
, self
->target
)
238 case SOLVER_RULE_RPM_IMPLICIT_OBSOLETES
:
239 snprintf(s
, STRING_SIZE
- 1,
240 _("package %s implicitely obsoletes %s provided by %s"),
241 pool_solvid2str(pool
, self
->source
), pool_dep2str(pool
, self
->dep
),
242 pool_solvid2str(pool
, self
->target
)
246 case SOLVER_RULE_RPM_PACKAGE_REQUIRES
:
247 snprintf(s
, STRING_SIZE
- 1,
248 _("package %s requires %s, but none of the providers can be installed"),
249 pool_solvid2str(pool
, self
->source
), pool_dep2str(pool
, self
->dep
)
253 case SOLVER_RULE_RPM_SELF_CONFLICT
:
254 snprintf(s
, STRING_SIZE
- 1,
255 _("package %s conflicts with %s provided by itself"),
256 pool_solvid2str(pool
, self
->source
), pool_dep2str(pool
, self
->dep
)
260 case SOLVER_RULE_UNKNOWN
:
261 case SOLVER_RULE_FEATURE
:
262 case SOLVER_RULE_LEARNT
:
263 case SOLVER_RULE_CHOICE
:
264 snprintf(s
, STRING_SIZE
- 1, _("bad rule type"));
269 return Py_BuildValue("s", &s
);