]> git.ipfire.org Git - pakfire.git/commitdiff
Add some lines that were supposed to report problems of the solver if any.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Apr 2011 16:38:03 +0000 (16:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Apr 2011 16:38:03 +0000 (16:38 +0000)
This doesn't work, but I wanted to save the code.

pakfire/repository/solver.py
po/pakfire.pot

index b9f5772a012f8e79699ab234e20f9d65a0f1af6a..a34b82ce348fcbce65e456e63c7f087edeba484d 100644 (file)
@@ -136,7 +136,7 @@ class Solver(object):
        def create_request(self):
                return self.pool.create_request()
 
-       def solve(self, request):
+       def solve(self, request, interactive=False):
                solver = self.pool.create_solver()
                solver.set_allow_uninstall(True)
 
@@ -159,13 +159,66 @@ class Solver(object):
                        # Solver had an error and we now see what we can do:
                        logging.info("The solver returned %s problems." % solver.problems_count())
 
-                       for p in solver.problems(request):
-                               logging.info("Problem: %s" % p)
-                               for s in p.solutions():
-                                       s = "%s" % s
-                                       logging.info(s.strip())
+                       # XXX everything after this line is totally broken and does not do its
+                       # job correctly.
+                       return
 
-                       break
+                       jobactions = {
+                               satsolver.INSTALL_SOLVABLE : "install",
+                               satsolver.UPDATE_SOLVABLE  : "update",
+                               satsolver.REMOVE_SOLVABLE  : "remove",
+                       }
+
+                       problem_count = 0
+                       for problem in solver.problems(request):
+                               problem_count += 1
+
+                               # A data structure to store the solution to the key that is
+                               # the user supposed to press.
+                               solutionmap = {}
+
+                               logging.warning(" Problem %s: %s" % (problem_count, problem))
+
+                               solution_count = 0
+                               for solution in problem.solutions():
+                                       solution_count += 1
+                                       solutionmap[solution_count] = solution
+
+                                       logging.info("  [%2d]: %s" % (solution_count, solution))
+
+                               if not interactive:
+                                       continue
+
+                               logging.info("  - %s -" % _("Empty to abort."))
+
+                               while True:
+                                       print _("Choose a solution:"),
+
+                                       ret = raw_input()
+                                       # If the user has entered nothing, we abort the operation.
+                                       if not ret:
+                                               return
+
+                                       try:
+                                               ret = int(ret)
+                                       except ValueError:
+                                               ret = None
+
+                                       # Get the selected solution from the map.
+                                       solution = solutionmap.get(ret, None)
+
+                                       if not solution:
+                                               print _("You have entered an invalid solution. Try again.")
+                                               continue
+
+                                       else:
+                                               jobs = [e.job() for e in solution.elements()]
+                                               for job in jobs:
+                                                       try:
+                                                               print jobactions[job.cmd()]
+                                                       except KeyError:
+                                                               raise Exception, "Unknown action called."
+                                               break
 
        def solvables2packages(self, solvables):
                pkgs = []
index 7e8fcb8555e5422ca7b5170260b6237dd8bf9b06..637ed212df7973f8ce5b58cf9b77861fdb9a40bc 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-04-30 12:49+0000\n"
+"POT-Creation-Date: 2011-04-30 16:33+0000\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -90,6 +90,18 @@ msgstr ""
 msgid "Loading %s"
 msgstr ""
 
+#: ../pakfire/repository/solver.py:188
+msgid "Empty to abort."
+msgstr ""
+
+#: ../pakfire/repository/solver.py:191
+msgid "Choose a solution:"
+msgstr ""
+
+#: ../pakfire/repository/solver.py:207
+msgid "You have entered an invalid solution. Try again."
+msgstr ""
+
 #: ../pakfire/repository/transaction.py:107
 #, python-format
 msgid "Cleanup: %s"