}
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;
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);
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);
}
"""
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
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"))
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()
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"))
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)