def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.add_option("--urls", action="store_true", help=_("show URLs")) parser.add_option("--paths", action="store_true", help=_("show path list")) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES, version="smart %s" % VERSION) parser.disable_interspersed_args() parser.add_option( "--config-file", metavar=_("FILE"), help=_("configuration file " "(default is <data-dir>/config)") ) parser.add_option("--data-dir", metavar=_("DIR"), help=_("data directory (default is %s)") % DATADIR) parser.add_option( "--log-level", metavar=_("LEVEL"), help=_("set the log level to LEVEL (debug, info, " "warning, error)") ) parser.add_option("--gui", action="store_true", help=_("use the default graphic interface")) parser.add_option("--shell", action="store_true", help=_("use the default shell interface")) parser.add_option("--interface", metavar=_("NAME"), help=_("use the given interface")) parser.add_option("--ignore-locks", action="store_true", help=_("don't respect locking")) parser.add_option( "-o", "--option", action="append", default=[], metavar=_("OPT"), help=_("set the option given by a name=value pair"), ) opts, args = parser.parse_args() if args: opts.command = args[0] opts.argv = args[1:] else: opts.command = None opts.argv = [] if not (opts.command or opts.gui or opts.shell): parser.print_help() sys.exit(1) return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.add_option("--stepped", action="store_true", help=_("split operation in steps")) parser.add_option("--urls", action="store_true", help=_("dump needed urls and don't commit operation")) parser.add_option("--download", action="store_true", help=_("download packages and don't commit operation")) parser.add_option("--update", action="store_true", help=_("update channel information before trying " "to upgrade")) parser.add_option("--check", action="store_true", help=_("just check if there are upgrades to be done")) parser.add_option("--check-update", action="store_true", help=_("check if there are upgrades to be done, and " "update the known upgrades")) parser.add_option("--explain", action="store_true", help=_("include additional information about changes," "when possible")) parser.add_option("-y", "--yes", action="store_true", help=_("do not ask for confirmation")) parser.add_option("--dump", action="store_true", help=_("dump package names and versions to stderr but " "don't commit operation")) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.defaults["add"] = [] parser.defaults["remove"] = [] parser.defaults["remove_all"] = [] parser.defaults["clear_history"] = None parser.add_option("--show", action="store_true", help=_("show current mirrors")) parser.add_option("--add", action="callback", callback=append_all, help=_("add to the given origin URL the given mirror " "URL, provided either in pairs, or in a given " "file/url in the format used by --show")) parser.add_option("--remove", action="callback", callback=append_all, help=_("remove from the given origin URL the given " "mirror URL, provided either in pairs, or in a " "given file/url in the format used by --show")) parser.add_option("--remove-all", action="callback", callback=append_all, help=_("remove all mirrors for the given origin URLs")) parser.add_option("--sync", action="store", metavar="FILE", help=_("synchronize mirrors from the given file/url, " "so that origins in the given file will have " "exactly the specified mirrors")) parser.add_option("--clear-history", action="callback", callback=append_all, help=_("clear history for the given origins/mirrors, or " "for all mirrors")) parser.add_option("--show-penalities", action="store_true", help=_("show current penalities for origins/mirrors, " "based on the history information")) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) opts, args = parser.parse_args(argv) opts.args = args return opts
def do_remove(self, line): args = shlex.split(line) parser = OptionParser(add_help_option=False) parser.add_option("--explain", action="store_true") opts, args = parser.parse_args(args) cache = self._ctrl.getCache() transaction = Transaction(cache, policy=PolicyRemove) transaction.setState(self._changeset) changeset = transaction.getChangeSet() policy = transaction.getPolicy() expected = 0 for arg, pkgs in self.pkgsFromArgs(args): expected += 1 found = False for pkg in pkgs: if pkg.installed: found = True transaction.enqueue(pkg, REMOVE) for _pkg in cache.getPackages(pkg.name): if not _pkg.installed: policy.setLocked(_pkg, True) if not found: raise Error, _("'%s' matches no installed packages") % arg transaction.run() if opts.explain: self.setExplain(True) if iface.confirmChange(self._changeset, changeset, expected): self.saveUndo() self._changeset.setState(changeset) if opts.explain: self.setExplain(False)
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.defaults["set"] = [] parser.defaults["remove"] = [] parser.defaults["show"] = None parser.add_option("--set", action="callback", callback=append_all, help=_("set flags given in pairs of flag name/target, " "where targets may use just the package " "name, or the package name, relation, and " "version, such as: lock 'python > 1.0'")) parser.add_option("--remove", action="callback", callback=append_all, help=_("remove flags given in pairs of flag name/target, " "where targets may use just the package " "name, or the package name, relation, and " "version, such as: lock 'python > 1.0'")) parser.add_option("--show", action="callback", callback=append_all, help=_("show packages with the flags given as arguments " "or all flags if no argument was given")) parser.add_option("--force", action="store_true", help=_("ignore problems")) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.defaults["set"] = [] parser.defaults["remove"] = [] parser.defaults["show"] = None parser.add_option("--set", action="callback", callback=append_all, help=_("set flags given in pairs of flag name/target, " "where targets may use just the package " "name, or the package name, relation, and " "version, such as: lock 'python > 1.0'")) parser.add_option("--remove", action="callback", callback=append_all, help=_( "remove flags given in pairs of flag name/target, " "where targets may use just the package " "name, or the package name, relation, and " "version, such as: lock 'python > 1.0'")) parser.add_option("--show", action="callback", callback=append_all, help=_("show packages with the flags given as arguments " "or all flags if no argument was given")) parser.add_option("--force", action="store_true", help=_("ignore problems")) opts, args = parser.parse_args(argv) opts.args = args return opts
def do_reinstall(self, line): args = shlex.split(line) parser = OptionParser(add_help_option=False) parser.add_option("--explain", action="store_true") opts, args = parser.parse_args(args) cache = self._ctrl.getCache() transaction = Transaction(cache, policy=PolicyInstall) transaction.setState(self._changeset) changeset = transaction.getChangeSet() expected = 0 for arg, pkgs in self.pkgsFromArgs(args): expected += 1 if not pkgs: raise Error, _("'%s' matches no installed packages") % arg if len(pkgs) > 1: raise Error, _( "'%s' matches multiple installed packages") % arg transaction.enqueue(pkgs[0], REINSTALL) transaction.run() if opts.explain: self.setExplain(True) if iface.confirmChange(self._changeset, changeset, expected): self.saveUndo() self._changeset.setState(changeset) if opts.explain: self.setExplain(False)
def do_upgrade(self, line): args = shlex.split(line) parser = OptionParser(add_help_option=False) parser.add_option("--explain", action="store_true") opts, args = parser.parse_args(args) cache = self._ctrl.getCache() transaction = Transaction(cache, policy=PolicyUpgrade) transaction.setState(self._changeset) changeset = transaction.getChangeSet() expected = 0 if not args: for pkg in cache.getPackages(): if pkg.installed: transaction.enqueue(pkg, UPGRADE) else: for arg, pkgs in self.pkgsFromArgs(args): expected += 1 found = False for pkg in pkgs: if pkg.installed: found = True transaction.enqueue(pkg, UPGRADE) if not found: raise Error, _("'%s' matches no installed packages") % arg transaction.run() if opts.explain: self.setExplain(True) if changeset == self._changeset: print _("No interesting upgrades available!") elif iface.confirmChange(self._changeset, changeset, expected): self.saveUndo() self._changeset.setState(changeset) if opts.explain: self.setExplain(False)
def do_keep(self, line): args = shlex.split(line) parser = OptionParser(add_help_option=False) parser.add_option("--explain", action="store_true") opts, args = parser.parse_args(args) cache = self._ctrl.getCache() transaction = Transaction(cache, policy=PolicyInstall) transaction.setState(self._changeset) changeset = transaction.getChangeSet() expected = 0 for arg, pkgs in self.pkgsFromArgs(args): expected += 1 pkgs = [x for x in pkgs if x in changeset] if not pkgs: raise Error, _("'%s' matches no marked packages") % arg for pkg in pkgs: transaction.enqueue(pkg, KEEP) transaction.run() if opts.explain: self.setExplain(True) if iface.confirmChange(self._changeset, changeset, expected): self.saveUndo() self._changeset.setState(changeset) if opts.explain: self.setExplain(False)
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.add_option("--stepped", action="store_true", help=_("split operation in steps")) parser.add_option("--urls", action="store_true", help=_("dump needed urls and don't commit operation")) parser.add_option("--download", action="store_true", help=_("download packages and don't commit operation")) parser.add_option("--check", action="store_true", help=_("just check if there are upgrades to be done")) parser.add_option("--check-update", action="store_true", help=_("check if there are upgrades to be done, and " "update the known upgrades")) parser.add_option("-y", "--yes", action="store_true", help=_("do not ask for confirmation")) opts, args = parser.parse_args(argv) opts.args = args return opts
def do_reinstall(self, line): args = shlex.split(line) parser = OptionParser(add_help_option=False) parser.add_option("--explain", action="store_true") opts, args = parser.parse_args(args) cache = self._ctrl.getCache() transaction = Transaction(cache, policy=PolicyInstall) transaction.setState(self._changeset) changeset = transaction.getChangeSet() expected = 0 for arg, pkgs in self.pkgsFromArgs(args): expected += 1 if not pkgs: raise Error, _("'%s' matches no installed packages") % arg if len(pkgs) > 1: raise Error, _("'%s' matches multiple installed packages")%arg transaction.enqueue(pkgs[0], REINSTALL) transaction.run() if opts.explain: self.setExplain(True) if iface.confirmChange(self._changeset, changeset, expected): self.saveUndo() self._changeset.setState(changeset) if opts.explain: self.setExplain(False)
def do_install(self, line): args = shlex.split(line) parser = OptionParser(add_help_option=False) parser.add_option("--explain", action="store_true") opts, args = parser.parse_args(args) cache = self._ctrl.getCache() transaction = Transaction(cache, policy=PolicyInstall) transaction.setState(self._changeset) changeset = transaction.getChangeSet() expected = 0 for arg, pkgs in self.pkgsFromArgs(args): expected += 1 names = {} found = False 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: found = True transaction.enqueue(pkg, INSTALL) if not found: raise Error, _("No uninstalled packages matched '%s'") % arg transaction.run() if opts.explain: self.setExplain(True) if iface.confirmChange(self._changeset, changeset, expected): self.saveUndo() self._changeset.setState(changeset) if opts.explain: self.setExplain(False)
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.defaults["set"] = [] parser.defaults["remove"] = [] parser.defaults["show"] = None parser.add_option("--set", action="callback", callback=append_all, help=_("set given key=value options")) parser.add_option("--show", action="callback", callback=append_all, help=_("show given options")) parser.add_option("--remove", action="callback", callback=append_all, help=_("remove given options")) parser.add_option("--force", action="store_true", help=_("ignore problems")) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES, skipunknown=True, add_help_option=False, version="smart %s" % VERSION) parser.add_option("--config-file", metavar=_("FILE"), help=_("configuration file " "(default is <data-dir>/config)")) parser.add_option("--rootfs-dir", metavar=_("DIR"), help=_("rootfs directory")) parser.add_option("--data-dir", metavar=_("DIR"), help=_("data directory (default is %s)") % DATADIR) parser.add_option("--log-level", metavar=_("LEVEL"), help=_("set the log level to LEVEL (debug, info, " "warning, error)")) parser.add_option("--gui", action="store_true", help=_("use the default graphic interface")) parser.add_option("--shell", action="store_true", help=_("use the default shell interface")) parser.add_option("--quiet", action="store_true", help=_("use the quiet interface")) parser.add_option("--interface", metavar=_("NAME"), help=_("use the given interface")) parser.add_option("--ignore-locks", action="store_true", help=_("don't respect locking")) parser.add_option("-o", "--option", action="append", default=[], metavar=_("OPT"), help=_("set the option given by a name=value pair")) opts, args = parser.parse_args() if args: opts.command = arg = args[0] opts.argv = args[1:] if arg and arg[0] == "-": if arg == "-h" or len(arg) > 2 and "--help".startswith(arg): parser.print_help() sys.exit(0) else: raise Error, _("no such option: %s") % arg else: opts.command = None opts.argv = [] if not (opts.command or opts.gui or opts.shell or opts.interface): parser.print_help() sys.exit(1) return opts
def parse_options(argv): description = DESCRIPTION % {"types": build_types()} parser = OptionParser(usage=USAGE, description=description, examples=EXAMPLES) parser.defaults["add"] = [] parser.defaults["set"] = [] parser.defaults["remove"] = [] parser.defaults["enable"] = [] parser.defaults["disable"] = [] parser.defaults["show"] = None parser.add_option("--add", action="callback", callback=append_all, help=_("argument is an alias and one or more " "key=value pairs defining a channel, or a " "filename/url pointing to a channel description " "in the same format used by --show, or a " "directory path where autodetection will be " "tried")) parser.add_option("--set", action="callback", callback=append_all, help=_("argument is an alias, and one or more key=value " "pairs modifying a channel")) parser.add_option("--remove", action="callback", callback=append_all, help=_("arguments are channel aliases to be removed")) parser.add_option("--show", action="callback", callback=append_all, help=_("show channels with given aliases, or all " "channels if no arguments were given")) parser.add_option("--edit", action="store_true", help=_("edit channels in editor set by $EDITOR")) parser.add_option("--enable", action="callback", callback=append_all, help=_("enable channels with given aliases")) parser.add_option("--disable", action="callback", callback=append_all, help=_("disable channels with given aliases")) parser.add_option("-y", "--yes", action="store_true", help=_("execute without asking")) parser.add_option("--help-type", action="store", metavar="TYPE", help=_("show further information about given type")) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.add_option("--after", metavar="MIN", type="int", help=_("only update if the last successful update " "happened before the given delay")) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv, help=None): if help: parser = OptionParser(help=help) else: parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.add_option("--all", action="store_true", help=_("check uninstalled packages as well")) parser.add_option("--uninstalled", action="store_true", help=_("check only uninstalled packages")) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.add_option("--stepped", action="store_true", help=_("split operation in steps")) parser.add_option("--urls", action="store_true", help=_("dump needed urls and don't commit operation")) parser.add_option("--download", action="store_true", help=_("download packages and don't commit operation")) parser.add_option("-y", "--yes", action="store_true", help=_("do not ask for confirmation")) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.add_option("--set", action="store_true", help=_("set priority")) parser.add_option("--remove", action="store_true", help=_("unset priority")) parser.add_option("--show", action="store_true", help=_("show priorities")) parser.add_option("--force", action="store_true", help=_("ignore problems")) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES, version="smart %s" % VERSION) parser.disable_interspersed_args() parser.add_option("--config-file", metavar=_("FILE"), help=_("configuration file " "(default is <data-dir>/config)")) parser.add_option("--data-dir", metavar=_("DIR"), help=_("data directory (default is %s)") % DATADIR) parser.add_option("--log-level", metavar=_("LEVEL"), help=_("set the log level to LEVEL (debug, info, " "warning, error)")) parser.add_option("--gui", action="store_true", help=_("use the default graphic interface")) parser.add_option("--shell", action="store_true", help=_("use the default shell interface")) parser.add_option("--interface", metavar=_("NAME"), help=_("use the given interface")) parser.add_option("--ignore-locks", action="store_true", help=_("don't respect locking")) parser.add_option("-o", "--option", action="append", default=[], metavar=_("OPT"), help=_("set the option given by a name=value pair")) opts, args = parser.parse_args() if args: opts.command = args[0] opts.argv = args[1:] else: opts.command = None opts.argv = [] if not (opts.command or opts.gui or opts.shell): parser.print_help() sys.exit(1) return opts
def parse_options(argv): parser = OptionParser( usage=USAGE, description=DESCRIPTION, examples=EXAMPLES, skipunknown=True, add_help_option=False, version="smart %s" % VERSION, ) parser.add_option( "--config-file", metavar=_("FILE"), help=_("configuration file " "(default is <data-dir>/config)") ) parser.add_option("--data-dir", metavar=_("DIR"), help=_("data directory (default is %s)") % DATADIR) parser.add_option( "--log-level", metavar=_("LEVEL"), help=_("set the log level to LEVEL (debug, info, " "warning, error)") ) parser.add_option("--gui", action="store_true", help=_("use the default graphic interface")) parser.add_option("--shell", action="store_true", help=_("use the default shell interface")) parser.add_option("--interface", metavar=_("NAME"), help=_("use the given interface")) parser.add_option("--ignore-locks", action="store_true", help=_("don't respect locking")) parser.add_option( "-o", "--option", action="append", default=[], metavar=_("OPT"), help=_("set the option given by a name=value pair"), ) opts, args = parser.parse_args() if args: opts.command = arg = args[0] opts.argv = args[1:] if arg and arg[0] == "-": if arg == "-h" or len(arg) > 2 and "--help".startswith(arg): parser.print_help() sys.exit(0) else: raise Error, _("no such option: %s") % arg else: opts.command = None opts.argv = [] if not (opts.command or opts.gui or opts.shell or opts.interface): parser.print_help() sys.exit(1) return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.defaults["from_urls"] = [] parser.defaults["target"] = os.getcwd() parser.add_option("--target", action="store", metavar="DIR", help=_("packages will be saved in given directory")) parser.add_option("--urls", action="store_true", help=_("dump needed urls and don't download packages")) parser.add_option("--from-urls", action="callback", callback=append_all, help=_("download files from the given urls and/or from " "the given files with lists of urls")) opts, args = parser.parse_args(argv) opts.args = args if not os.path.isdir(opts.target): raise Error, _("Directory not found:"), opts.target return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.add_option("--all", action="store_true", help=_("check packages in all channels")) parser.add_option("--installed", action="store_true", help=_("check packages which are in at least " "one installed channel (default)")) parser.add_option("--available", action="store_true", help=_("check packages which are in at least " "one non-installed channel")) parser.add_option("--channels", action="store", metavar="ALIASES", help=_("check packages which are inside the " "given channels (comma separated aliases)")) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv): description = DESCRIPTION % {"types": build_types()} parser = OptionParser(usage=USAGE, description=description, examples=EXAMPLES) parser.defaults["add"] = None parser.defaults["set"] = None parser.defaults["remove"] = None parser.defaults["enable"] = None parser.defaults["disable"] = None parser.defaults["show"] = None parser.add_option("--add", action="callback", callback=append_all, help=_("argument is an alias and one or more " "key=value pairs defining a channel, or a " "filename/url pointing to a channel description " "in the same format used by --show, or a " "directory path where autodetection will be " "tried")) parser.add_option("--set", action="callback", callback=append_all, help=_("argument is an alias, and one or more key=value " "pairs modifying a channel")) parser.add_option("--remove", action="callback", callback=append_all, help=_("arguments are channel aliases to be removed")) parser.add_option("--remove-all", action="store_true", help=_("remove all existent channels")) parser.add_option("--show", action="callback", callback=append_all, help=_("show channels with given aliases, or all " "channels if no arguments were given")) parser.add_option("--edit", action="store_true", help=_("edit channels in editor set by $EDITOR")) parser.add_option("--enable", action="callback", callback=append_all, help=_("enable channels with given aliases")) parser.add_option("--disable", action="callback", callback=append_all, help=_("disable channels with given aliases")) parser.add_option("-y", "--yes", action="store_true", help=_("execute without asking")) parser.add_option("--help-type", action="store", metavar="TYPE", help=_("show further information about given type")) opts, args = parser.parse_args(argv) opts.args = args return opts
def do_fix(self, line): args = shlex.split(line) parser = OptionParser(add_help_option=False) parser.add_option("--explain", action="store_true") opts, args = parser.parse_args(args) cache = self._ctrl.getCache() transaction = Transaction(cache, policy=PolicyInstall) transaction.setState(self._changeset) changeset = transaction.getChangeSet() expected = 0 for arg, pkgs in self.pkgsFromArgs(args): expected += 1 for pkg in pkgs: transaction.enqueue(pkg, FIX) transaction.run() if opts.explain: self.setExplain(True) if changeset == self._changeset: print _("No problems to resolve!") elif iface.confirmChange(self._changeset, changeset, expected): self.saveUndo() self._changeset.setState(changeset) if opts.explain: self.setExplain(False)
def do_ls(self, line): args = shlex.split(line) parser = OptionParser(add_help_option=False) parser.add_option("-i", action="store_true", dest="installed") parser.add_option("-v", action="store_true", dest="version") parser.add_option("-s", action="store_true", dest="summary") parser.add_option("-n", action="store_true", dest="new") opts, args = parser.parse_args(args) if args: pkgs = {} for arg in args: ratio, results, suggestions = self._ctrl.search( arg, addprovides=False) if not results: if suggestions: dct = {} for r, obj in suggestions: if isinstance(obj, Package): dct[obj] = True else: dct.update(dct.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 else: for obj in results: if isinstance(obj, Package): pkgs[obj] = True else: pkgs.update(dict.fromkeys(obj.packages, True)) else: pkgs = self._ctrl.getCache().getPackages() if opts.installed: pkgs = [x for x in pkgs if x.installed] if opts.new: pkgs = pkgconf.filterByFlag("new", pkgs) pkgs = dict.fromkeys(pkgs).keys() pkgs.sort() if opts.summary: for pkg in pkgs: if opts.version: print str(pkg), "-", else: print pkg.name, "-", for loader in pkg.loaders: info = loader.getInfo(pkg) summary = info.getSummary() if summary: print summary break else: print return maxnamelen = 0 for pkg in pkgs: if opts.version: namelen = len(str(pkg)) else: namelen = len(pkg.name) if namelen > maxnamelen: maxnamelen = namelen screenwidth = getScreenWidth() perline = screenwidth / (maxnamelen + 2) if perline == 0: perline = 1 columnlen = screenwidth / perline numpkgs = len(pkgs) numlines = (numpkgs + perline - 1) / perline blank = " " * columnlen out = sys.stdout for line in range(numlines): for entry in range(perline): k = line + (entry * numlines) if k >= numpkgs: break pkg = pkgs[k] s = opts.version and str(pkg) or pkg.name out.write(s) out.write(" " * (columnlen - len(s))) print
def do_ls(self, line): args = shlex.split(line) parser = OptionParser(add_help_option=False) parser.add_option("-i", action="store_true", dest="installed") parser.add_option("-a", action="store_true", dest="available") parser.add_option("-v", action="store_true", dest="version") parser.add_option("-s", action="store_true", dest="summary") parser.add_option("-n", action="store_true", dest="new") opts, args = parser.parse_args(args) if args: pkgs = {} for arg in args: ratio, results, suggestions = self._ctrl.search(arg, addprovides=False) if not results: if suggestions: dct = {} for r, obj in suggestions: if isinstance(obj, Package): dct[obj] = True else: dct.update(dct.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 else: for obj in results: if isinstance(obj, Package): pkgs[obj] = True else: pkgs.update(dict.fromkeys(obj.packages, True)) else: pkgs = self._ctrl.getCache().getPackages() if opts.installed and opts.available: raise Error, _("-i and -a options conflict") % arg if opts.installed: pkgs = [x for x in pkgs if x.installed] if opts.available: pkgs = [x for x in pkgs if not x.installed] if opts.new: pkgs = pkgconf.filterByFlag("new", pkgs) pkgs = dict.fromkeys(pkgs).keys() pkgs.sort() if opts.summary: for pkg in pkgs: if opts.version: print str(pkg), "-", else: print pkg.name, "-", for loader in pkg.loaders: info = loader.getInfo(pkg) summary = info.getSummary() if summary: print summary break else: print return maxnamelen = 0 for pkg in pkgs: if opts.version: namelen = len(str(pkg)) else: namelen = len(pkg.name) if namelen > maxnamelen: maxnamelen = namelen screenwidth = getScreenWidth() perline = screenwidth/(maxnamelen+2) if perline == 0: perline = 1 columnlen = screenwidth/perline numpkgs = len(pkgs) numlines = (numpkgs+perline-1)/perline blank = " "*columnlen out = sys.stdout for line in range(numlines): for entry in range(perline): k = line+(entry*numlines) if k >= numpkgs: break pkg = pkgs[k] s = opts.version and str(pkg) or pkg.name out.write(s) out.write(" "*(columnlen-len(s))) print
def parse_options(argv): parser = OptionParser(usage=USAGE) opts, args = parser.parse_args(argv) opts.args = args return opts
def parse_options(argv, help=None): if help: parser = OptionParser(help=help) else: parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.add_option("--installed", action="store_true", help=_("consider only installed packages")) parser.add_option("--provides", action="append", default=[], metavar="DEP", help=_("show only packages providing the given " "dependency")) parser.add_option("--requires", action="append", default=[], metavar="DEP", help=_("show only packages requiring the given " "dependency")) parser.add_option("--conflicts", action="append", default=[], metavar="DEP", help=_("show only packages conflicting with the given " "dependency")) parser.add_option("--upgrades", action="append", default=[], metavar="DEP", help=_("show only packages upgrading the given " "dependency")) parser.add_option("--name", action="append", default=[], metavar="STR", help=_("show only packages which match given name")) parser.add_option("--summary", action="append", default=[], metavar="STR", help=_("show only packages which match given summary")) parser.add_option("--description", action="append", default=[], metavar="STR", help=_("show only packages which match given " "description")) parser.add_option("--path", action="append", default=[], metavar="STR", help=_("show only packages which include the given " "path in the available meta information")) parser.add_option("--url", action="append", default=[], metavar="STR", help=_("show only packages which include the given " "reference url in the available meta " "information")) parser.add_option("--hide-version", action="store_true", help=_("hide package version")) parser.add_option("--show-summary", action="store_true", help=_("show package summaries")) parser.add_option("--show-provides", action="store_true", help=_("show provides for the given packages")) parser.add_option("--show-requires", action="store_true", help=_("show requires for the given packages")) parser.add_option("--show-prerequires", action="store_true", help=_("show requires selecting only pre-dependencies")) parser.add_option("--show-upgrades", action="store_true", help=_("show upgrades for the given packages")) parser.add_option("--show-conflicts", action="store_true", help=_("show conflicts for the given packages")) parser.add_option("--show-providedby", action="store_true", help=_("show packages providing dependencies")) parser.add_option("--show-requiredby", action="store_true", help=_("show packages requiring provided information")) parser.add_option("--show-upgradedby", action="store_true", help=_("show packages upgrading provided information")) parser.add_option("--show-conflictedby", action="store_true", help=_("show packages conflicting with provided " "information")) parser.add_option("--show-priority", action="store_true", help=_("show package priority")) parser.add_option("--show-channels", action="store_true", help=_("show channels that include this package")) parser.add_option("--show-all", action="store_true", help=_("enable all --show-* options")) parser.add_option("--format", action="store", default="text", metavar="FMT", help=_("change output format")) parser.add_option("--output", action="store", metavar="FILE", help=_("redirect output to given filename")) opts, args = parser.parse_args(argv) opts.args = args if opts.show_all: for attr in dir(opts): if attr.startswith("show_"): setattr(opts, attr, True) return opts
def parse_options(argv, help=None): if help: parser = OptionParser(help=help) else: parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES) parser.add_option("--installed", action="store_true", help=_("consider only installed packages")) parser.add_option("--provides", action="append", default=[], metavar="DEP", help=_("show only packages providing the given " "dependency")) parser.add_option("--requires", action="append", default=[], metavar="DEP", help=_("show only packages requiring the given " "dependency")) parser.add_option("--conflicts", action="append", default=[], metavar="DEP", help=_("show only packages conflicting with the given " "dependency")) parser.add_option("--upgrades", action="append", default=[], metavar="DEP", help=_("show only packages upgrading the given " "dependency")) parser.add_option("--name", action="append", default=[], metavar="STR", help=_("show only packages which match given name")) parser.add_option("--summary", action="append", default=[], metavar="STR", help=_("show only packages which match given summary")) parser.add_option("--description", action="append", default=[], metavar="STR", help=_("show only packages which match given " "description")) parser.add_option("--path", action="append", default=[], metavar="STR", help=_("show only packages which include the given " "path in the available meta information")) parser.add_option("--url", action="append", default=[], metavar="STR", help=_("show only packages which include the given " "reference url in the available meta " "information")) parser.add_option("--hide-version", action="store_true", help=_("hide package version")) parser.add_option("--show-summary", action="store_true", help=_("show package summaries")) parser.add_option("--show-provides", action="store_true", help=_("show provides for the given packages")) parser.add_option("--show-requires", action="store_true", help=_("show requires for the given packages")) parser.add_option("--show-prerequires", action="store_true", help=_("show requires selecting only pre-dependencies")) parser.add_option("--show-upgrades", action="store_true", help=_("show upgrades for the given packages")) parser.add_option("--show-conflicts", action="store_true", help=_("show conflicts for the given packages")) parser.add_option("--show-providedby", action="store_true", help=_("show packages providing dependencies")) parser.add_option("--show-requiredby", action="store_true", help=_("show packages requiring provided information")) parser.add_option("--show-upgradedby", action="store_true", help=_("show packages upgrading provided information")) parser.add_option("--show-conflictedby", action="store_true", help=_("show packages conflicting with provided " "information")) parser.add_option("--show-priority", action="store_true", help=_("show package priority")) parser.add_option("--show-channels", action="store_true", help=_("show channels that include this package")) parser.add_option("--show-all", action="store_true", help=_("enable all --show-* options")) parser.add_option("--format", action="store", default="text", metavar="FMT", help=_("change output format")) parser.add_option("--output", action="store", metavar="FILE", help=_("redirect output to given filename")) opts, args = parser.parse_args(argv) opts.args = args if opts.show_all: for attr in dir(opts): if attr.startswith("show_") and attr != "show_prerequires": setattr(opts, attr, True) return opts