def actOnPackages(self, pkgs, op=None): cache = self._ctrl.getCache() transaction = Transaction(cache, policy=PolicyInstall) transaction.setState(self._changeset) changeset = transaction.getChangeSet() if op is None: if not [pkg for pkg in pkgs if pkg not in changeset]: op = KEEP else: for pkg in pkgs: if not pkg.installed: op = INSTALL break else: op = REMOVE if op is REMOVE: transaction.setPolicy(PolicyRemove) policy = transaction.getPolicy() for pkg in pkgs: if op is KEEP: transaction.enqueue(pkg, op) elif op in (REMOVE, REINSTALL, FIX): if pkg.installed: transaction.enqueue(pkg, op) if op is REMOVE: for _pkg in cache.getPackages(pkg.name): if not _pkg.installed: policy.setLocked(_pkg, True) elif op is INSTALL: if not pkg.installed: transaction.enqueue(pkg, op) transaction.run() if op is FIX: expected = 0 else: expected = 1 if self.confirmChange(self._changeset, changeset, expected): self.saveUndo() self._changeset.setState(changeset) pkgs.extend(changeset) self.changedMarks(pkgs)
def main(ctrl, opts): ctrl.reloadChannels() cache = ctrl.getCache() trans = Transaction(cache, PolicyRemove) policy = trans.getPolicy() for arg in opts.args: ratio, results, suggestions = ctrl.search(arg) if not results: if suggestions: dct = {} for r, obj in suggestions: if isinstance(obj, Package): if obj.installed: dct[obj] = True else: for pkg in obj.packages: if pkg.installed: dct[pkg] = True if not dct: del suggestions[:] if suggestions: raise Error, _("'%s' matches no packages. " "Suggestions:\n%s") % \ (arg, "\n".join([" "+str(x) for x in dct])) else: raise Error, _("'%s' matches no packages") % arg pkgs = [] for obj in results: if isinstance(obj, Package): pkgs.append(obj) if not pkgs: for obj in results: for pkg in obj.packages: pkgs.append(pkg) found = False for pkg in pkgs: if pkg.installed: found = True trans.enqueue(pkg, REMOVE) else: policy.setLocked(pkg, True) if not found: iface.warning(_("'%s' matches no installed packages") % arg) iface.showStatus(_("Computing transaction...")) trans.run() iface.hideStatus() if trans: confirm = not opts.yes if opts.urls: ctrl.dumpTransactionURLs(trans) elif opts.download: ctrl.downloadTransaction(trans, confirm=confirm) elif opts.stepped: ctrl.commitTransactionStepped(trans, confirm=confirm) else: ctrl.commitTransaction(trans, confirm=confirm)
def main(ctrl, opts): # Argument check if not opts.args: raise Error, _("no package(s) given") if opts.explain: sysconf.set("explain-changesets", True, soft=True) if sysconf.get("auto-update"): from smart.commands import update updateopts = update.parse_options([]) update.main(ctrl, updateopts) else: ctrl.reloadChannels() cache = ctrl.getCache() trans = Transaction(cache, PolicyRemove) policy = trans.getPolicy() if opts.auto: rmcs = ctrl.markAndSweep() confirm = not opts.yes ctrl.commitChangeSet(rmcs, confirm=confirm) for arg in opts.args: ratio, results, suggestions = ctrl.search(arg) if not results: if suggestions: dct = {} for r, obj in suggestions: if isinstance(obj, Package): if obj.installed: dct[obj] = True else: for pkg in obj.packages: if pkg.installed: dct[pkg] = True if not dct: del suggestions[:] if suggestions: raise Error, _("'%s' matches no packages. " "Suggestions:\n%s") % \ (arg, "\n".join([" "+str(x) for x in dct])) else: raise Error, _("'%s' matches no packages") % arg pkgs = [] for obj in results: if isinstance(obj, Package): pkgs.append(obj) if not pkgs: for obj in results: for pkg in obj.packages: pkgs.append(pkg) found = False for pkg in pkgs: if pkg.installed: found = True trans.enqueue(pkg, REMOVE) else: policy.setLocked(pkg, True) if not found: iface.warning(_("'%s' matches no installed packages") % arg) iface.showStatus(_("Computing transaction...")) trans.run() iface.hideStatus() if trans: confirm = not opts.yes if opts.urls: ctrl.dumpTransactionURLs(trans) elif opts.metalink: ctrl.dumpTransactionMetalink(trans) elif opts.dump: ctrl.dumpTransactionPackages(trans, remove=True) elif opts.download: ctrl.downloadTransaction(trans, confirm=confirm) elif opts.stepped: ctrl.commitTransactionStepped(trans, confirm=confirm) else: ctrl.commitTransaction(trans, confirm=confirm)