]>
git.ipfire.org Git - pakfire.git/blob - python/pakfire/satsolver.py
2 ###############################################################################
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2011 Pakfire development team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
25 from _pakfire
import *
32 class Request(_pakfire
.Request
):
33 def install(self
, what
):
34 if isinstance(what
, Solvable
):
35 self
.install_solvable(what
)
38 elif isinstance(what
, Relation
):
39 self
.install_relation(what
)
42 elif type(what
) == type("string"):
43 self
.install_name(what
)
46 raise Exception, "Unknown type"
48 def remove(self
, what
):
49 if isinstance(what
, Solvable
):
50 self
.remove_solvable(what
)
53 elif isinstance(what
, Relation
):
54 self
.remove_relation(what
)
57 elif type(what
) == type("string"):
58 self
.remove_name(what
)
61 raise Exception, "Unknown type"
63 def update(self
, what
):
64 if isinstance(what
, Solvable
):
65 self
.update_solvable(what
)
68 elif isinstance(what
, Relation
):
69 self
.update_relation(what
)
72 elif type(what
) == type("string"):
73 self
.update_name(what
)
76 raise Exception, "Unknown type"
79 if isinstance(what
, Solvable
):
80 self
.lock_solvable(what
)
83 elif isinstance(what
, Relation
):
84 self
.lock_relation(what
)
87 elif type(what
) == type("string"):
91 raise Exception, "Unknown type"
93 def noobsoletes(self
, what
):
94 if isinstance(what
, Solvable
):
95 self
.noobsoletes_solvable(what
)
98 elif isinstance(what
, Relation
):
99 self
.noobsoletes_relation(what
)
102 elif type(what
) == type("string"):
103 self
.noobsoletes_name(what
)
106 raise Exception, "Unknown type"
109 class Solver(object):
110 def __init__(self
, pakfire
, pool
):
111 self
.pakfire
= pakfire
114 def solve(self
, request
, update
=False, uninstall
=False, allow_downgrade
=False,
115 allow_vendorchange
=False, allow_archchange
=False, fix_system
=False,
116 interactive
=False, logger
=None):
118 # If no logger was provided, we use the root logger.
120 logger
= logging
.getLogger()
122 # Create a new solver.
123 solver
= _pakfire
.Solver(self
.pool
)
125 solver
.set_fix_system(fix_system
)
126 solver
.set_allow_uninstall(uninstall
)
127 solver
.set_allow_downgrade(allow_downgrade
)
129 # Optionally allow packages to change their vendors.
130 # This is not recommended because it may have weird effects.
131 solver
.set_allow_vendorchange(allow_vendorchange
)
133 # Optionally allow packages ot change their architecture.
134 solver
.set_allow_archchange(allow_archchange
)
136 # Configure the solver for an update.
138 solver
.set_updatesystem(True)
139 solver
.set_do_split_provides(True)
141 # Actually solve the request.
142 res
= solver
.solve(request
)
144 logger
.debug("Solver status: %s" % res
)
146 # If the solver succeeded, we return the transaction and return.
148 # Return a resulting Transaction.
149 t
= Transaction(solver
)
151 return transaction
.Transaction
.from_solver(self
.pakfire
, self
, t
)
153 # Do the problem handling...
154 problems
= solver
.get_problems(request
)
157 logger
.info(_("The solver returned one problem:", "The solver returned %(num)s problems:",
158 len(problems
)) % { "num" : len(problems
) })
161 for problem
in problems
:
164 # Print information about the problem to the user.
165 logger
.info(" #%d: %s" % (i
, problem
))
172 # Ask the user if he or she want to modify the request. If not, just exit.
173 if not util
.ask_user(_("Do you want to manually alter the request?")):
176 print _("You can now try to satisfy the solver by modifying your request.")
180 if len(problems
) > 1:
181 print _("Which problem to you want to resolve?")
183 print _("Press enter to try to re-solve the request.")
184 print "[1-%s]:" % len(problems
),
188 # If the user did not enter anything, we abort immediately.
192 # If the user did type anything else than an integer, we ask
199 # If the user entered an integer outside of range, we ask
202 problem
= problems
[answer
- 1]
210 solutions
= problem
.get_solutions()
212 if len(solutions
) == 1:
213 solution
= solutions
[0]
214 print _(" Solution: %s") % solution
217 if util
.ask_user("Do you accept the solution above?"):
219 print "XXX do something"
223 print _(" Solutions:")
225 for solution
in solutions
:
227 print " #%d: %s" % (i
, solution
)
234 # If the request was altered by the user, we try to solve it again
235 # and see what happens.
236 return self
.solve(request
, update
=update
, uninstall
=uninstall
,
237 allow_downgrade
=allow_downgrade
, interactive
=interactive
)