From: Michael Tremer Date: Thu, 2 Nov 2017 18:06:01 +0000 (+0100) Subject: Add support to the solver to update X-Git-Tag: 0.9.28~1285^2~1322 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4785718431461560c49e65138e8f8f43401ec929;p=pakfire.git Add support to the solver to update Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/request.c b/src/_pakfire/request.c index df48b653d..9a59acc88 100644 --- a/src/_pakfire/request.c +++ b/src/_pakfire/request.c @@ -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; diff --git a/src/libpakfire/include/pakfire/request.h b/src/libpakfire/include/pakfire/request.h index 3b1f11c96..9343bbf58 100644 --- a/src/libpakfire/include/pakfire/request.h +++ b/src/libpakfire/include/pakfire/request.h @@ -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); diff --git a/src/libpakfire/request.c b/src/libpakfire/request.c index d8aaab6cb..f43211983 100644 --- a/src/libpakfire/request.c +++ b/src/libpakfire/request.c @@ -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); } diff --git a/src/pakfire/base.py b/src/pakfire/base.py index 89158dbbb..e4e4259f3 100644 --- a/src/pakfire/base.py +++ b/src/pakfire/base.py @@ -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 diff --git a/src/pakfire/cli.py b/src/pakfire/cli.py index 6de63c036..70f8c8d42 100644 --- a/src/pakfire/cli.py +++ b/src/pakfire/cli.py @@ -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)