Пример #1
0
 def parse_install_options(self):
     """Parse install command options."""
     self.insoptions = arghparse.Namespace()
     self.diroptions = arghparse.Namespace()
     if self.opts.insoptions:
         if not self._parse_install_options(self.opts.insoptions, self.insoptions):
             self.install = self._install_cmd().send
     if self.opts.diroptions:
         if not self._parse_install_options(self.opts.diroptions, self.diroptions):
             self.install_dirs = self._install_dirs_cmd().send
Пример #2
0
    def __call__(self, ebd):
        self.opts = arghparse.Namespace()
        self.ebd = ebd
        ret = 0

        # read info from bash side
        nonfatal = self.read() == 'true'
        self.cwd = self.read()
        options = shlex.split(self.read())
        args = self.read().strip('\0')
        args = args.split('\0') if args else []

        # parse args and run command
        with chdir(self.cwd):
            try:
                args = self.parse_args(options, args)
                ret = self.run(args)
            except IpcCommandError as e:
                if nonfatal:
                    ret = (e.code, e.msg)
                else:
                    raise IpcCommandError(msg=e.msg,
                                          code=e.code,
                                          name=self.name)
            except KeyboardInterrupt:
                raise
            except Exception as e:
                raise IpcInternalError('internal failure') from e

        # return completion status to the bash side
        self.write(self._encode_ret(ret))
Пример #3
0
 def process_check(self, *args, **kwds):
     namespace = arghparse.Namespace()
     repo_config = repo_objs.RepoConfig(location=self.dir)
     namespace.target_repo = repository.UnconfiguredTree(
         repo_config.location, repo_config=repo_config)
     namespace.search_repo = Options()
     namespace.cache = {'profiles': False}
     options = ArgparseCheck.process_check(self, namespace=namespace, *args, **kwds)
     return options
Пример #4
0
def test_check_scope(tool):
    """Verify check scopes match their source scopes."""
    namespace = arghparse.Namespace()
    # forcibly enable all checks so none are skipped
    namespace.forced_checks = [name for name, _cls in const.CHECKS.items()]
    options, _func = tool.parse_args(['scan'], namespace)
    enabled_checks, _ = init_checks(options.addons, options)
    for scope, d in enabled_checks.items():
        for (source, is_async), runners in d.items():
            for check in runners:
                assert check.scope == source.feed_type, \
                    f"check scope doesn't match source scope: {check}"
Пример #5
0
    def parse(self, *args, **kwargs):
        """Parse a commandline and return the Values object.

        args are passed to parse_args, keyword args are used as config keys.
        """
        ns_kwargs = kwargs.pop('ns_kwargs', {})
        namespace = kwargs.get('namespace', arghparse.Namespace(**ns_kwargs))
        if self.has_config:
            if kwargs.pop("suppress_domain", self.suppress_domain):
                kwargs["default_domain"] = default_domain
            namespace.config = self._mk_config([kwargs], debug=True)
        namespace = self.parser.parse_args(list(args), namespace=namespace)
        return namespace
Пример #6
0
 def test_bool(self):
     namespace = arghparse.Namespace()
     assert not namespace
     namespace.arg = 'foo'
     assert namespace
Пример #7
0
def namespace():
    """Return an arghparse Namespace object."""
    return arghparse.Namespace()