]> git.ipfire.org Git - pakfire.git/commitdiff
Add support to the solver to update
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Nov 2017 18:06:01 +0000 (19:06 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Nov 2017 18:06:01 +0000 (19:06 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/request.c
src/libpakfire/include/pakfire/request.h
src/libpakfire/request.c
src/pakfire/base.py
src/pakfire/cli.py

index df48b653d4ae3954860afad591845e3e47e8366e..9a59acc8881d6672c36cdf6e6375d271d01ee752 100644 (file)
@@ -209,13 +209,33 @@ static PyObject* Request_get_problems(RequestObject* self) {
 }
 
 static PyObject* Request_solve(RequestObject* self, PyObject* args, PyObject *kwds) {
-       char* kwlist[] = {"without_recommends", NULL};
+       char* kwlist[] = {"allow_archchange", "allow_downgrade", "allow_uninstall",
+               "allow_vendorchange", "without_recommends", NULL};
 
+       int allow_archchange = 0;
+       int allow_downgrade = 0;
+       int allow_uninstall = 0;
+       int allow_vendorchange = 0;
        int without_recommends = 0;
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "|p", kwlist, &without_recommends))
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ppppp", kwlist,
+                       &allow_archchange, &allow_downgrade, &allow_uninstall,
+                       &allow_vendorchange, &without_recommends))
                return NULL;
 
        int flags = 0;
+       if (allow_archchange)
+               flags |= PAKFIRE_SOLVER_ALLOW_ARCHCHANGE;
+
+       if (allow_downgrade)
+               flags |= PAKFIRE_SOLVER_ALLOW_DOWNGRADE;
+
+       if (allow_uninstall)
+               flags |= PAKFIRE_SOLVER_ALLOW_UNINSTALL;
+
+       if (allow_vendorchange)
+               flags |= PAKFIRE_SOLVER_ALLOW_VENDORCHANGE;
+
        if (without_recommends)
                flags |= PAKFIRE_SOLVER_WITHOUT_RECOMMENDS;
 
index 3b1f11c96dfc0e4a9c0fc9ec1544d3e3d41c4166..9343bbf584b8ac243fab4cc10e033ab1d4a8401c 100644 (file)
@@ -36,6 +36,9 @@ enum _pakfire_solver_flags {
        PAKFIRE_SOLVER_ALLOW_UNINSTALL    = 1 << 0,
        PAKFIRE_SOLVER_FORCE_BEST         = 1 << 1,
        PAKFIRE_SOLVER_WITHOUT_RECOMMENDS = 1 << 2,
+       PAKFIRE_SOLVER_ALLOW_ARCHCHANGE   = 1 << 3,
+       PAKFIRE_SOLVER_ALLOW_DOWNGRADE    = 1 << 4,
+       PAKFIRE_SOLVER_ALLOW_VENDORCHANGE = 1 << 5,
 };
 
 PakfireRequest pakfire_request_create(PakfirePool pool);
index d8aaab6cb948e018d61707cac90a20f21d1c9b9f..f432119835645071607ed6689025cb665bd062c3 100644 (file)
@@ -84,16 +84,21 @@ static void init_solver(PakfireRequest request, int flags) {
 
        request->solver = solver;
 
+       if (flags & PAKFIRE_SOLVER_ALLOW_ARCHCHANGE)
+               solver_set_flag(solver, SOLVER_FLAG_ALLOW_ARCHCHANGE, 1);
+
+       if (flags & PAKFIRE_SOLVER_ALLOW_DOWNGRADE)
+               solver_set_flag(solver, SOLVER_FLAG_ALLOW_DOWNGRADE, 1);
+
        if (flags & PAKFIRE_SOLVER_ALLOW_UNINSTALL)
                solver_set_flag(solver, SOLVER_FLAG_ALLOW_UNINSTALL, 1);
 
-       /* ignore recommends */
+       if (flags & PAKFIRE_SOLVER_ALLOW_VENDORCHANGE)
+               solver_set_flag(solver, SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
+
        if (flags & PAKFIRE_SOLVER_WITHOUT_RECOMMENDS)
                solver_set_flag(solver, SOLVER_FLAG_IGNORE_RECOMMENDED, 1);
 
-       /* no vendor locking */
-       solver_set_flag(solver, SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
-
        /* no arch change for forcebest */
        solver_set_flag(solver, SOLVER_FLAG_BEST_OBEY_POLICY, 1);
 }
index 89158dbbbdbd3cecf618cf526a2519218d800bab..e4e4259f33af9af4505560a92e1f9604c291f58b 100644 (file)
@@ -266,63 +266,24 @@ class PakfireContext(object):
                """
                raise NotImplementedError
 
-       def update(self, pkgs=None, check=False, excludes=None, interactive=True, logger=None, sync=False, **kwargs):
-               """
-                       check indicates, if the method should return after calculation
-                       of the transaction.
-               """
-               if logger is None:
-                       logger = logging.getLogger("pakfire")
+       def update(self, reqs=None, excludes=None, **kwargs):
+               request = _pakfire.Request(self.pakfire.pool)
 
-               # If there are given any packets on the command line, we will
-               # only update them. Otherwise, we update the whole system.
-               updateall = True
-               if pkgs:
-                       updateall = False
+               # Add all packages that should be updated to the request
+               for req in reqs or []:
+                       relation = _pakfire.Relation(self.pakfire.pool, req)
+                       request.upgrade(relation)
 
-               request = self.pakfire.pool.create_request(update=pkgs, updateall=updateall)
+               # Otherwise we will try to upgrade everything
+               else:
+                       request.upgrade_all()
 
-               # Exclude packages that should not be updated.
+               # Exclude packages that should not be updated
                for exclude in excludes or []:
-                       logger.info(_("Excluding %s.") % exclude)
-
-                       exclude = self.pakfire.pool.create_relation(exclude)
-                       request.lock(exclude)
-
-               # Update or downgrade to the latest version of all packages
-               # in the enabled repositories.
-               if sync:
-                       kwargs.update({
-                               "allow_downgrade" : True,
-                               "allow_uninstall" : True,
-                       })
-
-               solver = self.pakfire.pool.solve(request, logger=logger, **kwargs)
-
-               if not solver.status:
-                       logger.info(_("Nothing to do"))
+                       relation = _pakfire.Relation(self.pakfire.pool, exclude)
+                       request.lock(relation)
 
-                       # If we are running in check mode, we return a non-zero value to
-                       # indicate, that there are no updates.
-                       if check:
-                               return 1
-                       else:
-                               return
-
-               # Create the transaction.
-               t = transaction.Transaction.from_solver(self.pakfire, solver)
-               t.dump(logger=logger)
-
-               # Just exit here, because we won't do the transaction in this mode.
-               if check:
-                       return
-
-               # Ask the user if the transaction is okay.
-               if interactive and not t.cli_yesno():
-                       return
-
-               # Run the transaction.
-               t.run(logger=logger)
+               return request.solve(**kwargs)
 
        def downgrade(self, pkgs, logger=None, **kwargs):
                assert pkgs
index 6de63c036c78260aa3c079849e0e62dc10dd9965..70f8c8d42121033e559a551c2c27e45b4cfadf2f 100644 (file)
@@ -72,10 +72,12 @@ class Cli(object):
                check_update.set_defaults(func=self.handle_check_update)
                check_update.add_argument("--exclude", "-x", nargs="+",
                        help=_("Exclude package from update"))
+               check_update.add_argument("--allow-archchange", action="store_true",
+                       help=_("Allow changing the architecture of packages"))
+               check_update.add_argument("--allow-downgrade", action="store_true",
+                       help=_("Allow downgrading of packages"))
                check_update.add_argument("--allow-vendorchange", action="store_true",
                        help=_("Allow changing the vendor of packages"))
-               check_update.add_argument("--disallow-archchange", action="store_true",
-                       help=_("Disallow changing the architecture of packages"))
 
                # clean
                clean = subparsers.add_parser("clean", help=_("Cleanup all temporary files"))
@@ -164,11 +166,13 @@ class Cli(object):
                update.add_argument("package", nargs="*",
                        help=_("Give a name of a package to update or leave emtpy for all"))
                update.add_argument("--exclude", "-x", nargs="+",
-                       help=_("Exclude package from update."))
+                       help=_("Exclude package from update"))
+               update.add_argument("--allow-archchange", action="store_true",
+                       help=_("Allow changing the architecture of packages"))
+               update.add_argument("--allow-downgrade", action="store_true",
+                       help=_("Allow downgrading of packages"))
                update.add_argument("--allow-vendorchange", action="store_true",
-                       help=_("Allow changing the vendor of packages."))
-               update.add_argument("--disallow-archchange", action="store_true",
-                       help=_("Disallow changing the architecture of packages."))
+                       help=_("Allow changing the vendor of packages"))
                update.set_defaults(func=self.handle_update)
 
                return parser.parse_args()
@@ -248,12 +252,18 @@ class Cli(object):
 
                        return e.exit_code
 
-       def _execute_transaction(self, transaction):
-               # Dump transaction
+       def _dump_transaction(self, transaction):
+               """
+                       Dumps the transaction
+               """
                t = transaction.dump()
+
                for line in t.splitlines():
                        self.ui.message(line)
 
+       def _execute_transaction(self, transaction):
+               self._dump_transaction(transaction)
+
                # Ask the user to confirm to go ahead
                if not self.ui.confirm():
                        self.ui.message(_("Aborted by user"))
@@ -273,21 +283,31 @@ class Cli(object):
                                s = pkg.dump(short=True)
                                print(s)
 
-       def handle_update(self, **args):
-               p = self.create_pakfire()
-
-               packages = getattr(self.args, "package", [])
+       def handle_update(self, ns, check=False):
+               with self.pakfire(ns) as p:
+                       transaction = p.update(
+                               ns.package, excludes=ns.exclude,
+                               allow_archchange=ns.allow_archchange,
+                               allow_vendorchange=ns.allow_vendorchange,
+                       )
 
-               args.update({
-                       "allow_archchange"   : not self.args.disallow_archchange,
-                       "allow_vendorchange" : self.args.allow_vendorchange,
-                       "excludes"           : self.args.exclude,
-               })
+                       # If we are only checking for updates,
+                       # we dump the transaction and exit here.
+                       if check:
+                               self._dump_transaction(transaction)
+                               return
 
-               p.update(packages, **args)
+                       # Otherwise we execute the transaction
+                       self._execute_transaction(transaction)
 
        def handle_sync(self, ns):
-               self.handle_update(ns, sync=True)
+               with self.pakfire(ns) as p:
+                       transaction = p.update(
+                               allow_archchange=True,
+                               allow_vendorchange=True,
+                       )
+
+                       self._execute_transaction(transaction)
 
        def handle_check_update(self, ns):
                self.handle_update(ns, check=True)