def main(ctrl, opts): packages = [] if opts.args: ctrl.reloadChannels() cache = ctrl.getCache() packages = {} 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): dct[obj] = True else: dct.update(dict.fromkeys(obj.packages, True)) 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: installed = False names = {} for obj in results: for pkg in obj.packages: if pkg.installed: iface.warning( _("%s (for %s) is already installed") % (pkg, arg)) installed = True break else: pkgs.append(pkg) names[pkg.name] = True else: continue break if installed: continue if len(names) > 1: raise Error, _("There are multiple matches for '%s':\n%s") % \ (arg, "\n".join([" "+str(x) for x in pkgs])) if len(pkgs) > 1: sortUpgrades(pkgs) names = {} for pkg in pkgs: names.setdefault(pkg.name, []).append(pkg) for name in names: packages[names[name][0]] = True packages = packages.keys() if opts.urls: ctrl.dumpURLs(packages) else: ctrl.downloadPackages(packages, targetdir=opts.target) elif opts.from_urls: urls = [] for arg in opts.from_urls: if ":/" in arg: urls.append(arg) elif os.path.isfile(arg): urls.extend([x.strip() for x in open(arg)]) else: raise Error, _("Argument is not a file nor url: %s") % arg ctrl.downloadURLs(urls, _("URLs"), targetdir=opts.target)
def main(ctrl, opts): # Argument check if not opts.args: raise Error, _("no package(s) given") if opts.attempt: sysconf.set("attempt-install", True, soft=True) if opts.explain: sysconf.set("explain-changesets", True, soft=True) urls = [] for arg in opts.args[:]: if (os.path.isfile(arg) and '/' in arg or ctrl.checkPackageFile(arg)): ctrl.addFileChannel(arg) opts.args.remove(arg) elif ":/" in arg: urls.append(arg) if urls: succ, fail = ctrl.downloadURLs(urls, _("packages"), targetdir=os.getcwd()) if fail: raise Error, _("Failed to download packages:\n") + \ "\n".join([" %s: %s" % (url, fail[url]) for url in fail]) for url, file in succ.items(): ctrl.addFileChannel(file) opts.args.remove(url) 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, PolicyInstall) for channel in ctrl.getFileChannels(): for loader in channel.getLoaders(): for pkg in loader.getPackages(): if pkg.installed: raise Error, _("%s is already installed") % pkg trans.enqueue(pkg, INSTALL) 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): dct[obj] = True else: dct.update(dict.fromkeys(obj.packages, True)) 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: installed = False names = {} for obj in results: for pkg in obj.packages: if pkg.installed: iface.info( _("%s (for %s) is already installed") % (pkg, arg)) installed = True break else: pkgs.append(pkg) names[pkg.name] = True else: continue break if installed: continue if len(names) == 2 and sysconf.get("rpm-strict-multilib"): from smart.backends.rpm.rpmver import splitarch # two packages with the same version but different arch, pick best if splitarch(pkgs[0].version)[0] == splitarch( pkgs[1].version)[0]: pkg = max(pkgs[0], pkgs[1]) names.pop(pkg.name) pkgs.remove(pkg) if len(names) > 1: raise Error, _("There are multiple matches for '%s':\n%s") % \ (arg, "\n".join([" "+str(x) for x in pkgs])) if len(pkgs) > 1: sortUpgrades(pkgs) names = {} for pkg in pkgs: names.setdefault(pkg.name, []).append(pkg) for name in names: pkg = names[name][0] if pkg.installed: iface.info(_("%s is already installed") % pkg) else: trans.enqueue(pkg, INSTALL) 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, install=True) 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.attempt: sysconf.set("attempt-install", True, soft=True) if opts.explain: sysconf.set("explain-changesets", True, soft=True) urls = [] for arg in opts.args[:]: if (os.path.isfile(arg) and '/' in arg or ctrl.checkPackageFile(arg)): ctrl.addFileChannel(arg) opts.args.remove(arg) elif ":/" in arg: urls.append(arg) if urls: succ, fail = ctrl.downloadURLs(urls, _("packages"), targetdir=os.getcwd()) if fail: raise Error, _("Failed to download packages:\n") + \ "\n".join([" %s: %s" % (url, fail[url]) for url in fail]) for url, file in succ.items(): ctrl.addFileChannel(file) opts.args.remove(url) 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, PolicyInstall) for channel in ctrl.getFileChannels(): for loader in channel.getLoaders(): for pkg in loader.getPackages(): if pkg.installed: raise Error, _("%s is already installed") % pkg trans.enqueue(pkg, INSTALL) 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): dct[obj] = True else: dct.update(dict.fromkeys(obj.packages, True)) 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: installed = False names = {} for obj in results: for pkg in obj.packages: if pkg.installed: iface.info(_("%s (for %s) is already installed") % (pkg, arg)) installed = True break else: pkgs.append(pkg) names[pkg.name] = True else: continue break if installed: continue if len(names) == 2 and sysconf.get("rpm-strict-multilib"): from smart.backends.rpm.rpmver import splitarch # two packages with the same version but different arch, pick best if splitarch(pkgs[0].version)[0] == splitarch(pkgs[1].version)[0]: pkg = max(pkgs[0], pkgs[1]) names.pop(pkg.name) pkgs.remove(pkg) if len(names) > 1: raise Error, _("There are multiple matches for '%s':\n%s") % \ (arg, "\n".join([" "+str(x) for x in pkgs])) if len(pkgs) > 1: sortUpgrades(pkgs) names = {} for pkg in pkgs: names.setdefault(pkg.name, []).append(pkg) for name in names: pkg = names[name][0] if pkg.installed: iface.info(_("%s is already installed") % pkg) else: trans.enqueue(pkg, INSTALL) 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, install=True) 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): if opts.explain: sysconf.set("explain-changesets", True, soft=True) urls = [] for arg in opts.args[:]: if (os.path.isfile(arg) and '/' in arg or filter(None, hooks.call("check-package-file", arg))): ctrl.addFileChannel(arg) opts.args.remove(arg) elif ":/" in arg: urls.append(arg) if urls: succ, fail = ctrl.downloadURLs(urls, _("packages"), targetdir=os.getcwd()) if fail: raise Error, _("Failed to download packages:\n") + \ "\n".join([" %s: %s" % (url, fail[url]) for url in fail]) for url, file in succ.items(): ctrl.addFileChannel(file) opts.args.remove(url) ctrl.reloadChannels() cache = ctrl.getCache() trans = Transaction(cache, PolicyInstall) for channel in ctrl.getFileChannels(): for loader in channel.getLoaders(): for pkg in loader.getPackages(): if pkg.installed: raise Error, _("%s is already installed") % pkg trans.enqueue(pkg, INSTALL) 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): dct[obj] = True else: dct.update(dict.fromkeys(obj.packages, True)) 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: installed = False names = {} for obj in results: for pkg in obj.packages: if pkg.installed: iface.warning(_("%s (for %s) is already installed") % (pkg, arg)) installed = True break else: pkgs.append(pkg) names[pkg.name] = True else: continue break if installed: continue if len(names) > 1: raise Error, _("There are multiple matches for '%s':\n%s") % \ (arg, "\n".join([" "+str(x) for x in pkgs])) if len(pkgs) > 1: sortUpgrades(pkgs) names = {} for pkg in pkgs: names.setdefault(pkg.name, []).append(pkg) for name in names: pkg = names[name][0] if pkg.installed: iface.warning(_("%s is already installed") % pkg) else: trans.enqueue(pkg, INSTALL) iface.showStatus(_("Computing transaction...")) trans.run() iface.hideStatus() if trans: confirm = not opts.yes print opts.urls, opts.dump, opts.download, opts.stepped, confirm if opts.urls: ctrl.dumpTransactionURLs(trans) elif opts.dump: ctrl.dumpTransactionPackages(trans, install=True) 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 opts.check_args_of_option("target", 1) opts.check_args_of_option("output", 1) opts.check_args_of_option("from_urls", -1) opts.check_args_of_option("from_metalink", -1) if not opts.args and not opts.from_metalink and not opts.from_urls: raise Error, _("no package(s) given") packages = [] if opts.args: if sysconf.get("auto-update"): from smart.commands import update updateopts = update.parse_options([]) update.main(ctrl, updateopts) else: ctrl.reloadChannels() cache = ctrl.getCache() packages = {} 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): dct[obj] = True else: dct.update(dict.fromkeys(obj.packages, True)) 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: installed = False names = {} for obj in results: for pkg in obj.packages: if pkg.installed: iface.warning( _("%s (for %s) is already installed") % (pkg, arg)) installed = True break else: pkgs.append(pkg) names[pkg.name] = True else: continue break if installed: continue if len(names) > 1: raise Error, _("There are multiple matches for '%s':\n%s") % \ (arg, "\n".join([" "+str(x) for x in pkgs])) if len(pkgs) > 1: sortUpgrades(pkgs) names = {} for pkg in pkgs: names.setdefault(pkg.name, []).append(pkg) for name in names: packages[names[name][0]] = True packages = packages.keys() if opts.urls: ctrl.dumpURLs(packages) elif opts.metalink: ctrl.dumpMetalink(packages) else: ctrl.downloadPackages(packages, targetdir=opts.target) if opts.pack: ctrl.packPackages(packages, targetdir=opts.target, \ outputname=opts.output) elif opts.from_urls: urls = [] for arg in opts.from_urls: if ":/" in arg: urls.append(arg) elif os.path.isfile(arg): line = open(arg).readline() if line.startswith('<?xml'): # assume XML is metalink ctrl.downloadMetalink(arg, _("Metalink"), targetdir=opts.target) continue urls.extend([x.strip() for x in open(arg)]) else: raise Error, _("Argument is not a file nor url: %s") % arg if urls: ctrl.downloadURLs(urls, _("URLs"), targetdir=opts.target) elif opts.from_metalink: for arg in opts.from_metalink: ctrl.downloadMetalink(arg, _("Metalink"), targetdir=opts.target)
def main(ctrl, opts, policy=None): if not policy: policy = PolicyInstall urls = [] for arg in opts.args[:]: if (os.path.isfile(arg) and '/' in arg or filter(None, hooks.call("check-package-file", arg))): ctrl.addFileChannel(arg) opts.args.remove(arg) elif ":/" in arg: urls.append(arg) if urls: succ, fail = ctrl.downloadURLs(urls, _("packages"), targetdir=os.getcwd()) if fail: raise Error, _("Failed to download packages:\n") + \ "\n".join([" %s: %s" % (url, fail[url]) for url in fail]) for url, file in succ.items(): ctrl.addFileChannel(file) opts.args.remove(url) ctrl.reloadChannels() cache = ctrl.getCache() trans = Transaction(cache, policy) for channel in ctrl.getFileChannels(): for loader in channel.getLoaders(): for pkg in loader.getPackages(): if pkg.installed: raise Error, _("%s is already installed") % pkg trans.enqueue(pkg, INSTALL) 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): dct[obj] = True else: dct.update(dict.fromkeys(obj.packages, True)) 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: installed = False names = {} for obj in results: for pkg in obj.packages: if pkg.installed: iface.warning( _("%s (for %s) is already installed") % (pkg, arg)) installed = True break else: pkgs.append(pkg) names[pkg.name] = True else: continue break if installed: continue if len(names) > 1: raise Error, _("There are multiple matches for '%s':\n%s") % \ (arg, "\n".join([" "+str(x) for x in pkgs])) if len(pkgs) > 1: if pkgs[0].isPatch(): pkgs.sort() pkgs.reverse() else: sortUpgrades(pkgs) names = {} for pkg in pkgs: names.setdefault(pkg.name, []).append(pkg) for name in names: pkg = names[name][0] if pkg.installed: iface.warning(_("%s is already installed") % pkg) else: trans.enqueue(pkg, INSTALL) 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 opts.check_args_of_option("target", 1) opts.check_args_of_option("output", 1) opts.check_args_of_option("from_urls", -1) opts.check_args_of_option("from_metalink", -1) if not opts.args and not opts.from_metalink and not opts.from_urls: raise Error, _("no package(s) given") packages = [] if opts.args: if sysconf.get("auto-update"): from smart.commands import update updateopts = update.parse_options([]) update.main(ctrl, updateopts) else: ctrl.reloadChannels() cache = ctrl.getCache() packages = {} 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): dct[obj] = True else: dct.update(dict.fromkeys(obj.packages, True)) 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: installed = False names = {} for obj in results: for pkg in obj.packages: if pkg.installed: iface.warning(_("%s (for %s) is already installed") % (pkg, arg)) installed = True break else: pkgs.append(pkg) names[pkg.name] = True else: continue break if installed: continue if len(names) > 1: raise Error, _("There are multiple matches for '%s':\n%s") % \ (arg, "\n".join([" "+str(x) for x in pkgs])) if len(pkgs) > 1: sortUpgrades(pkgs) names = {} for pkg in pkgs: names.setdefault(pkg.name, []).append(pkg) for name in names: packages[names[name][0]] = True packages = packages.keys() if opts.urls: ctrl.dumpURLs(packages) elif opts.metalink: ctrl.dumpMetalink(packages) else: ctrl.downloadPackages(packages, targetdir=opts.target) if opts.pack: ctrl.packPackages(packages, targetdir=opts.target, \ outputname=opts.output) elif opts.from_urls: urls = [] for arg in opts.from_urls: if ":/" in arg: urls.append(arg) elif os.path.isfile(arg): line = open(arg).readline() if line.startswith('<?xml'): # assume XML is metalink ctrl.downloadMetalink(arg, _("Metalink"), targetdir=opts.target) continue urls.extend([x.strip() for x in open(arg)]) else: raise Error, _("Argument is not a file nor url: %s") % arg if urls: ctrl.downloadURLs(urls, _("URLs"), targetdir=opts.target) elif opts.from_metalink: for arg in opts.from_metalink: ctrl.downloadMetalink(arg, _("Metalink"), targetdir=opts.target)
def main(ctrl, opts): packages = [] if opts.args: ctrl.reloadChannels() cache = ctrl.getCache() packages = {} 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): dct[obj] = True else: dct.update(dict.fromkeys(obj.packages, True)) 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: installed = False names = {} for obj in results: for pkg in obj.packages: if pkg.installed: iface.warning(_("%s (for %s) is already installed") % (pkg, arg)) installed = True break else: pkgs.append(pkg) names[pkg.name] = True else: continue break if installed: continue if len(names) > 1: raise Error, _("There are multiple matches for '%s':\n%s") % \ (arg, "\n".join([" "+str(x) for x in pkgs])) if len(pkgs) > 1: sortUpgrades(pkgs) names = {} for pkg in pkgs: names.setdefault(pkg.name, []).append(pkg) for name in names: packages[names[name][0]] = True packages = packages.keys() if opts.urls: ctrl.dumpURLs(packages) else: ctrl.downloadPackages(packages, targetdir=opts.target) elif opts.from_urls: urls = [] for arg in opts.from_urls: if ":/" in arg: urls.append(arg) elif os.path.isfile(arg): urls.extend([x.strip() for x in open(arg)]) else: raise Error, _("Argument is not a file nor url: %s") % arg ctrl.downloadURLs(urls, _("URLs"), targetdir=opts.target)