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 #############################################################################*/
23 #include <solv/policy.h>
24 #include <solv/solverdebug.h>
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
,
36 tp_dealloc
: (destructor
)Solution_dealloc
,
37 tp_doc
: "Sat Solution objects",
38 tp_str
: (reprfunc
)Solution_string
,
41 PyObject
*Solution_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
) {
43 ProblemObject
*problem
;
46 if (!PyArg_ParseTuple(args
, "Oi", &problem
, &id
)) {
47 /* XXX raise exception */
51 self
= (SolutionObject
*)type
->tp_alloc(type
, 0);
53 self
->_solver
= problem
->_solver
;
54 self
->problem_id
= problem
->_id
;
58 return (PyObject
*)self
;
61 PyObject
*Solution_dealloc(SolutionObject
*self
) {
62 self
->ob_type
->tp_free((PyObject
*)self
);
67 PyObject
*Solution_string(SolutionObject
*self
) {
68 Pool
*pool
= self
->_solver
->pool
;
69 Solver
*solver
= self
->_solver
;
70 char str
[STRING_SIZE
];
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
;
83 switch (how
& SOLVER_JOBMASK
) {
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
));
92 snprintf(str
, STRING_SIZE
- 1, _("do not install %s"),
93 solver_select2str(pool
, select
, what
));
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
));
104 snprintf(str
, STRING_SIZE
- 1, _("do not deinstall %s"),
105 solver_select2str(pool
, select
, what
));
109 snprintf(str
, STRING_SIZE
- 1, _("do not install most recent version of %s"),
110 solver_select2str(pool
, select
, what
));
114 snprintf(str
, STRING_SIZE
- 1, _("do not lock %s"),
115 solver_select2str(pool
, select
, what
));
119 snprintf(str
, STRING_SIZE
- 1, _("do something different"));
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
));
129 snprintf(str
, STRING_SIZE
- 1, _("install %s despite the inferior architecture"),
130 pool_solvable2str(pool
, s
));
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
));
138 snprintf(str
, STRING_SIZE
- 1, _("install %s from excluded repository"),
139 pool_solvable2str(pool
, s
));
142 s
= pool
->solvables
+ p
;
143 sd
= rp
? pool
->solvables
+ rp
: 0;
146 int illegal
= policy_is_illegal(solver
, s
, sd
, 0);
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
));
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
));
157 if ((illegal
& POLICY_ILLEGAL_VENDORCHANGE
) != 0) {
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
));
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
));
169 snprintf(str
, STRING_SIZE
- 1, _("allow replacement of %s with %s"),
170 pool_solvable2str(pool
, s
), pool_solvable2str(pool
, sd
));
175 return Py_BuildValue("s", &str
);