示例#1
0
    def __init__(self, config=True, domain=True, **kwds):
        super(ArgumentParser, self).__init__(**kwds)

        if not self.suppress:
            if config:
                self.add_argument(
                    '--add-config',
                    nargs=3,
                    action='append',
                    metavar=('SECTION', 'KEY', 'VALUE'),
                    help='modify an existing configuration section')
                self.add_argument('--new-config',
                                  nargs=3,
                                  action='append',
                                  metavar=('SECTION', 'KEY', 'VALUE'),
                                  help='add a new configuration section')
                self.add_argument('--empty-config',
                                  action='store_true',
                                  default=False,
                                  help='do not load user/system configuration')
                self.add_argument('--config',
                                  metavar='PATH',
                                  dest='override_config',
                                  type=arghparse.existent_path,
                                  help='override location of config files')

                self.set_defaults(
                    config=arghparse.DelayedValue(store_config, 0))

            if domain:
                _mk_domain(self)
示例#2
0
    def test_collapse_delayed(self):
        def _delayed_val(namespace, attr, val):
            setattr(namespace, attr, val)

        self.parser.set_defaults(
            delayed=arghparse.DelayedValue(partial(_delayed_val, val=42)))
        namespace = self.parser.parse_args([])
        assert namespace.delayed == 42
示例#3
0
    def __init__(self,
                 suppress=False,
                 config=True,
                 domain=True,
                 script=None,
                 **kwds):
        super().__init__(suppress=suppress, script=script, **kwds)
        self.register('action', 'parsers', _SubParser)

        if not suppress:
            config_opts = self.add_argument_group("config options")
            if config:
                config_opts.add_argument(
                    '--add-config',
                    nargs=3,
                    action='append',
                    metavar=('SECTION', 'KEY', 'VALUE'),
                    help='modify an existing configuration section')
                config_opts.add_argument(
                    '--new-config',
                    nargs=3,
                    action='append',
                    metavar=('SECTION', 'KEY', 'VALUE'),
                    help='add a new configuration section')
                config_opts.add_argument(
                    '--empty-config',
                    action='store_true',
                    help='do not load user/system configuration')
                config_opts.add_argument(
                    '--config',
                    metavar='PATH',
                    dest='override_config',
                    type=arghparse.existent_path,
                    help='override location of config files')

                if script is not None:
                    try:
                        _, script_module = script
                    except TypeError:
                        raise ValueError(
                            "invalid script parameter, should be (__file__, __name__)"
                        )
                    project = script_module.split('.')[0]
                else:
                    project = __name__.split('.')[0]

                # TODO: figure out a better method for plugin registry/loading
                try:
                    plugins = import_module('.plugins', project)
                    global_config = get_plugins('global_config', plugins)
                    self.set_defaults(config=arghparse.DelayedValue(
                        partial(store_config, global_config=global_config)))
                except ImportError:
                    pass

            if domain:
                _mk_domain(config_opts)
示例#4
0
    def __init__(self,
                 suppress=False,
                 help=True,
                 config=True,
                 domain=True,
                 script=None,
                 **kwds):
        super().__init__(suppress=suppress, script=script, **kwds)
        self.register('action', 'parsers', _SubParser)

        if not suppress:
            config_opts = self.add_argument_group('config options')
            if config:
                config_opts.add_argument(
                    '--config',
                    action=_ConfigArg,
                    dest='config_path',
                    help='use custom config or skip loading system config'
                    if help else argparse.SUPPRESS,
                    docs="""
                        The path to a custom pkgcore config file or portage
                        config directory can be given to override loading the
                        default system config.

                        Alternatively, an argument of 'false' or 'no' will skip
                        loading the system config entirely if one exists.
                    """)

                if script is not None:
                    try:
                        _, script_module = script
                    except TypeError:
                        raise ValueError(
                            "invalid script parameter, should be (__file__, __name__)"
                        )
                    project = script_module.split('.')[0]
                else:
                    project = __name__.split('.')[0]

                # TODO: figure out a better method for plugin registry/loading
                kwargs = {}
                try:
                    plugins = import_module('.plugins', project)
                    kwargs['global_config'] = get_plugins(
                        'global_config', plugins)
                except ImportError:
                    # project doesn't bundle plugins
                    pass
                self.set_defaults(config=arghparse.DelayedValue(
                    partial(store_config, **kwargs)))

            if domain:
                _mk_domain(config_opts, help)
示例#5
0
    def __init__(self,
                 suppress=False,
                 help=True,
                 config=True,
                 domain=True,
                 script=None,
                 **kwds):
        super().__init__(suppress=suppress, script=script, **kwds)
        self.register('action', 'parsers', _SubParser)

        if not suppress:
            config_opts = self.add_argument_group("config options")
            if config:
                config_opts.add_argument(
                    '--empty-config',
                    action='store_true',
                    help='skip loading user/system pkgcore config'
                    if help else argparse.SUPPRESS)
                config_opts.add_argument('--config',
                                         metavar='PATH',
                                         dest='override_config',
                                         type=arghparse.existent_path,
                                         help='use custom pkgcore config file'
                                         if help else argparse.SUPPRESS)

                if script is not None:
                    try:
                        _, script_module = script
                    except TypeError:
                        raise ValueError(
                            "invalid script parameter, should be (__file__, __name__)"
                        )
                    project = script_module.split('.')[0]
                else:
                    project = __name__.split('.')[0]

                # TODO: figure out a better method for plugin registry/loading
                kwargs = {}
                try:
                    plugins = import_module('.plugins', project)
                    kwargs['global_config'] = get_plugins(
                        'global_config', plugins)
                except ImportError:
                    # project doesn't bundle plugins
                    pass
                self.set_defaults(config=arghparse.DelayedValue(
                    partial(store_config, **kwargs)))

            if domain:
                _mk_domain(config_opts, help)
示例#6
0
    def __init__(self, *args, **kwargs):
        self.priority = int(kwargs.pop("priority", self.default_priority))
        self.config_type = kwargs.pop("config_type", None)
        if self.config_type is None or not isinstance(self.config_type, str):
            raise ValueError("config_type must specified, and be a string")

        if kwargs.pop("get_default", False):
            kwargs["default"] = arghparse.DelayedValue(
                partial(self.store_default,
                        self.config_type,
                        option_string=kwargs.get('option_strings', [None])[0]),
                self.priority)

        self.store_name = kwargs.pop("store_name", False)
        self.writable = kwargs.pop("writable", None)
        self.target = argparse._StoreAction(*args, **kwargs)

        super(StoreConfigObject, self).__init__(*args, **kwargs)
示例#7
0
    def __init__(self,
                 config=True,
                 domain=True,
                 project=__name__.split('.')[0],
                 **kwds):
        super(ArgumentParser, self).__init__(**kwds)

        if not self.suppress:
            if config:
                self.add_argument(
                    '--add-config',
                    nargs=3,
                    action='append',
                    metavar=('SECTION', 'KEY', 'VALUE'),
                    help='modify an existing configuration section')
                self.add_argument('--new-config',
                                  nargs=3,
                                  action='append',
                                  metavar=('SECTION', 'KEY', 'VALUE'),
                                  help='add a new configuration section')
                self.add_argument('--empty-config',
                                  action='store_true',
                                  default=False,
                                  help='do not load user/system configuration')
                self.add_argument('--config',
                                  metavar='PATH',
                                  dest='override_config',
                                  type=arghparse.existent_path,
                                  help='override location of config files')

                # XXX: Figure out a better method for plugin registry/loading.
                plugins = import_module('.plugins', project)
                global_config = get_plugins('global_config', plugins)

                self.set_defaults(config=arghparse.DelayedValue(
                    partial(store_config, global_config=global_config), 0))

            if domain:
                _mk_domain(self)
示例#8
0
                                     color=False,
                                     description=__doc__)


def stdin_default(namespace, attr):
    if sys.stdin.isatty():
        raise ValueError("Refusing to read from stdin since it's a TTY")
    setattr(namespace, attr, sys.stdin)


argparser.add_argument(
    '-i',
    '--input',
    action='store',
    type=argparse.FileType(),
    default=arghparse.DelayedValue(stdin_default, 0),
    help='Filename to read the env from (uses stdin if omitted).')
filtering = argparser.add_argument_group("Environment filtering options")
filtering.add_argument(
    '-V',
    '--var-match',
    action='store_true',
    default=False,
    help="Invert the filtering- instead of removing a var if it matches "
    "remove all vars that do not match")
filtering.add_argument(
    '-F',
    '--func-match',
    action='store_true',
    default=False,
    help="Invert the filtering- instead of removing a function if it matches "
示例#9
0
def make_atom(value):
    return arghparse.DelayedValue(partial(_render_atom, value), 100)
示例#10
0
                   help="repo(s) to regenerate caches for")
regen_opts = regen.add_argument_group("subcommand options")
regen_opts.add_argument("--disable-eclass-caching",
                        action='store_true',
                        default=False,
                        help="""
        For regen operation, pkgcore internally turns on an optimization that
        caches eclasses into individual functions thus parsing the eclass only
        twice max per EBD processor. Disabling this optimization via this
        option results in ~2x slower regeneration. Disable it only if you
        suspect the optimization is somehow causing issues.
    """)
regen_opts.add_argument("-t",
                        "--threads",
                        type=int,
                        default=arghparse.DelayedValue(_get_default_jobs, 100),
                        help="number of threads to use",
                        docs="""
        Number of threads to use for regeneration, defaults to using all
        available processors.
    """)
regen_opts.add_argument(
    "--force",
    action='store_true',
    default=False,
    help=
    "force regeneration to occur regardless of staleness checks or repo settings"
)
regen_opts.add_argument(
    "--rsync",
    action='store_true',
示例#11
0
 def lazy_load_object(cls, config_type, key, priority=None):
     if priority is None:
         priority = cls.default_priority
     return arghparse.DelayedValue(
         partial(cls._lazy_load_object, config_type, key), priority)
示例#12
0
                metavar=None,
                type=None,
                bind='final_converter',
                help='match installed packages without best slotted version')
def pkg_upgrade(_value, namespace):
    pkgs = []
    for pkg in namespace.domain.all_installed_repos:
        matches = sorted(
            namespace.domain.all_source_repos.match(pkg.slotted_atom))
        if matches and matches[-1] != pkg:
            pkgs.append(matches[-1].versioned_atom)
    return packages.OrRestriction(*pkgs)


argparser.set_defaults(
    _fallback_all=arghparse.DelayedValue(_add_all_if_needed, priority=89))
argparser.set_defaults(query=commandline.BooleanQuery(
    _query_items, klass_type='and', priority=90))

output = argparser.add_argument_group('output options')
output.add_argument('-1',
                    '--first',
                    action='store_true',
                    help='stop when first match is found')
output.add_argument('-a',
                    '--atom',
                    action=arghparse.Expansion,
                    subst=(('--cpv', ), ),
                    help='print =cat/pkg-3 instead of cat/pkg-3.',
                    docs="""
        Output valid package atoms, e.g. =cat/pkg-3 instead of cat/pkg-3.