]> git.ipfire.org Git - pakfire.git/blob - python/src/solution.c
Rewrite the buildsystem of this package.
[pakfire.git] / python / src / solution.c
1 /*#############################################################################
2 # #
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2011 Pakfire development team #
5 # #
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. #
10 # #
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. #
15 # #
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/>. #
18 # #
19 #############################################################################*/
20
21 #include <Python.h>
22
23 #include <solv/policy.h>
24 #include <solv/solverdebug.h>
25
26 #include "config.h"
27 #include "problem.h"
28 #include "solution.h"
29
30 PyTypeObject SolutionType = {
31 PyObject_HEAD_INIT(NULL)
32 tp_name: "_pakfire.Solution",
33 tp_basicsize: sizeof(SolutionObject),
34 tp_flags: Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
35 tp_new: Solution_new,
36 tp_dealloc: (destructor)Solution_dealloc,
37 tp_doc: "Sat Solution objects",
38 tp_str: (reprfunc)Solution_string,
39 };
40
41 PyObject *Solution_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
42 SolutionObject *self;
43 ProblemObject *problem;
44 Id id;
45
46 if (!PyArg_ParseTuple(args, "Oi", &problem, &id)) {
47 /* XXX raise exception */
48 return NULL;
49 }
50
51 self = (SolutionObject *)type->tp_alloc(type, 0);
52 if (self != NULL) {
53 self->_solver = problem->_solver;
54 self->problem_id = problem->_id;
55 self->id = id;
56 }
57
58 return (PyObject *)self;
59 }
60
61 PyObject *Solution_dealloc(SolutionObject *self) {
62 self->ob_type->tp_free((PyObject *)self);
63
64 Py_RETURN_NONE;
65 }
66
67 PyObject *Solution_string(SolutionObject *self) {
68 Pool *pool = self->_solver->pool;
69 Solver *solver = self->_solver;
70 char str[STRING_SIZE];
71
72 Solvable *s, *sd;
73 Id p, rp;
74 Id how, what, select;
75
76 Id element = 0;
77 while ((element = solver_next_solutionelement(solver, self->problem_id, self->id, element, &p, &rp)) != 0) {
78 if (p == SOLVER_SOLUTION_JOB) {
79 how = solver->job.elements[rp - 1];
80 what = solver->job.elements[rp];
81 select = how & SOLVER_SELECTMASK;
82
83 switch (how & SOLVER_JOBMASK) {
84 case SOLVER_INSTALL:
85 if (select == SOLVER_SOLVABLE && solver->installed && pool->solvables[what].repo == solver->installed)
86 snprintf(str, STRING_SIZE - 1, _("do not keep %s installed"),
87 pool_solvid2str(pool, what));
88 else if (select == SOLVER_SOLVABLE_PROVIDES)
89 snprintf(str, STRING_SIZE - 1, _("do not install a solvable %s"),
90 solver_select2str(pool, select, what));
91 else
92 snprintf(str, STRING_SIZE - 1, _("do not install %s"),
93 solver_select2str(pool, select, what));
94 break;
95
96 case SOLVER_ERASE:
97 if (select == SOLVER_SOLVABLE && !(solver->installed && pool->solvables[what].repo == solver->installed))
98 snprintf(str, STRING_SIZE - 1, _("do not forbid installation of %s"),
99 pool_solvid2str(pool, what));
100 else if (select == SOLVER_SOLVABLE_PROVIDES)
101 snprintf(str, STRING_SIZE - 1, _("do not deinstall all solvables %s"),
102 solver_select2str(pool, select, what));
103 else
104 snprintf(str, STRING_SIZE - 1, _("do not deinstall %s"),
105 solver_select2str(pool, select, what));
106 break;
107
108 case SOLVER_UPDATE:
109 snprintf(str, STRING_SIZE - 1, _("do not install most recent version of %s"),
110 solver_select2str(pool, select, what));
111 break;
112
113 case SOLVER_LOCK:
114 snprintf(str, STRING_SIZE - 1, _("do not lock %s"),
115 solver_select2str(pool, select, what));
116 break;
117
118 default:
119 snprintf(str, STRING_SIZE - 1, _("do something different"));
120 break;
121 }
122
123 } else if (p == SOLVER_SOLUTION_INFARCH) {
124 s = pool->solvables + rp;
125 if (solver->installed && s->repo == solver->installed)
126 snprintf(str, STRING_SIZE - 1, _("keep %s despite the inferior architecture"),
127 pool_solvable2str(pool, s));
128 else
129 snprintf(str, STRING_SIZE - 1, _("install %s despite the inferior architecture"),
130 pool_solvable2str(pool, s));
131
132 } else if (p == SOLVER_SOLUTION_DISTUPGRADE) {
133 s = pool->solvables + rp;
134 if (solver->installed && s->repo == solver->installed)
135 snprintf(str, STRING_SIZE - 1, _("keep obsolete %s"),
136 pool_solvable2str(pool, s));
137 else
138 snprintf(str, STRING_SIZE - 1, _("install %s from excluded repository"),
139 pool_solvable2str(pool, s));
140
141 } else {
142 s = pool->solvables + p;
143 sd = rp ? pool->solvables + rp : 0;
144
145 if (sd) {
146 int illegal = policy_is_illegal(solver, s, sd, 0);
147
148 // XXX multiple if clauses can match here
149 if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
150 snprintf(str, STRING_SIZE - 1, _("allow downgrade of %s to %s"),
151 pool_solvable2str(pool, s), pool_solvable2str(pool, sd));
152
153 if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
154 snprintf(str, STRING_SIZE - 1, _("allow architecture change of %s to %s"),
155 pool_solvable2str(pool, s), pool_solvable2str(pool, sd));
156
157 if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0) {
158 if (sd->vendor)
159 snprintf(str, STRING_SIZE - 1, _("allow vendor change from '%s' (%s) to '%s' (%s)"),
160 pool_id2str(pool, s->vendor), pool_solvable2str(pool, s),
161 pool_id2str(pool, sd->vendor), pool_solvable2str(pool, sd));
162 else
163 snprintf(str, STRING_SIZE - 1, _("allow vendor change from '%s' (%s) to no vendor (%s)"),
164 pool_id2str(pool, s->vendor), pool_solvable2str(pool, s),
165 pool_solvable2str(pool, sd));
166 }
167
168 if (!illegal)
169 snprintf(str, STRING_SIZE - 1, _("allow replacement of %s with %s"),
170 pool_solvable2str(pool, s), pool_solvable2str(pool, sd));
171 }
172 }
173 }
174
175 return Py_BuildValue("s", &str);
176 }