From: Zac Medico Date: Sat, 3 Aug 2013 00:10:34 +0000 (-0700) Subject: portageq: portage.util._argparse X-Git-Tag: v2.2.0_alpha192~10 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4df4c27f33ad3a258eb667c502e7b57f2f9b486e;p=portage.git portageq: portage.util._argparse --- diff --git a/bin/portageq b/bin/portageq index d31ae34aa..0756cdb9c 100755 --- a/bin/portageq +++ b/bin/portageq @@ -20,7 +20,6 @@ try: except KeyboardInterrupt: sys.exit(128 + signal.SIGINT) -import optparse import os import types @@ -41,6 +40,7 @@ portage._internal_caller = True from portage import os from portage.eapi import eapi_has_repo_deps from portage.util import writemsg, writemsg_stdout +from portage.util._argparse import ArgumentParser portage.proxy.lazyimport.lazyimport(globals(), 're', 'subprocess', @@ -929,7 +929,7 @@ class HerdMatcher(object): return any(x in herds for x in metadata_xml.herds()) -def pquery(parser, pquery_option_groups, opts, args): +def pquery(parser, opts, args): """[options] [atom]+ Emulates a subset of Pkgcore's pquery tool. """ @@ -1122,7 +1122,81 @@ non_commands = frozenset(['elog', 'eval_atom_use', 'exithandler', 'main', 'usage commands = sorted(k for k, v in globals().items() \ if k not in non_commands and isinstance(v, types.FunctionType) and v.__module__ == "__main__") -def usage(argv, parser=None, pquery_option_groups=None): + +def add_pquery_arguments(parser): + pquery_option_groups = ( + ( + 'Repository matching options', + ( + { + "longopt": "--no-filters", + "action": "store_true", + "help": "no visibility filters (ACCEPT_KEYWORDS, package masking, etc)" + }, + { + "longopt": "--repo", + "help": "repo to use (default is PORTDIR if omitted)" + }, + { + "longopt": "--all-repos", + "help": "search all repos" + } + ) + ), + ( + 'Package matching options', + ( + { + "longopt": "--herd", + "action": "append", + "help": "exact match on a herd" + }, + { + "longopt": "--maintainer-email", + "action": "append", + "help": "comma-separated list of maintainer email regexes to search for" + } + ) + ), + ( + 'Output formatting', + ( + { + "shortopt": "-n", + "longopt": "--no-version", + "action": "store_true", + "help": "collapse multiple matching versions together" + }, + ) + ), + ) + + for group_title, opt_data in pquery_option_groups: + arg_group = parser.add_argument_group(group_title) + for opt_info in opt_data: + pargs = [] + try: + pargs.append(opt_info["shortopt"]) + except KeyError: + pass + try: + pargs.append(opt_info["longopt"]) + except KeyError: + pass + + kwargs = {} + try: + kwargs["action"] = opt_info["action"] + except KeyError: + pass + try: + kwargs["help"] = opt_info["help"] + except KeyError: + pass + arg_group.add_argument(*pargs, **kwargs) + + +def usage(argv): print(">>> Portage information query tool") print(">>> %s" % portage.VERSION) print(">>> Usage: portageq [