def _load_obj(self, sections, name): repo = name if not self.allow_name_lookup or repo in sections: # requested repo exists in the config pass elif name in self.allow_aliases and self.valid_repo_types[name]: # pull repos related to given alias return getattr(self.domain, self.valid_repo_types[name]) else: # name wasn't found, check repo aliases for it for repo_name, repo_obj in sections.items(): if repo in repo_obj.aliases: repo = repo_name break else: # try to add it as an external repo if self.allow_external_repos and os.path.exists(repo): try: configure = not self.repo_type.endswith('-raw') with suppress_logging(): repo_obj = self.domain.add_repo( repo, config=self.config, configure=configure) repo = repo_obj.repo_id except repo_errors.RepoError as e: raise argparse.ArgumentError(self, e) if hasattr(self.domain, '_' + self.repo_key): # force JIT-ed attr refresh to include newly added repo setattr(self.domain, '_' + self.repo_key, None) sections = getattr(self.domain, self.repo_key) return StoreConfigObject._load_obj(self, sections, repo)
def _load_obj(self, sections, name): repo = name if not self.allow_name_lookup or repo in sections: # requested repo exists in the config pass elif name in self.allow_aliases and self.valid_repo_types[name]: # pull repos related to given alias return getattr(self.domain, self.valid_repo_types[name]) else: # name wasn't found, check repo aliases for it for repo_name, repo_obj in sections.items(): if repo in repo_obj.aliases: repo = repo_name break else: # try to add it as an external repo if self.allow_external_repos and os.path.exists(repo): try: with suppress_logging(): repo_obj = self.domain.add_repo(repo, config=self.config) repo = repo_obj.repo_id except repo_errors.RepoError as e: raise argparse.ArgumentError(self, e) if hasattr(self.domain, '_' + self.repo_key): # force JIT-ed attr refresh to include newly added repo setattr(self.domain, '_' + self.repo_key, None) sections = getattr(self.domain, self.repo_key) return StoreConfigObject._load_obj(self, sections, repo)
def __call__(self, parser, namespace, values, option_string=None): if self.separator is not None: values = values.split(self.separator) if self.use_sets: setattr(namespace, self.use_sets, []) if isinstance(values, str): values = [values] elif values is not None and len(values) == 1 and values[0] == '-': if not sys.stdin.isatty(): values = [x.strip() for x in sys.stdin.readlines() if x.strip() != ''] # reassign stdin to allow interactivity (currently only works for unix) sys.stdin = open('/dev/tty') else: raise argparse.ArgumentError(self, "'-' is only valid when piping data in") # override default empty tuple value to appendable list if values: setattr(namespace, self.dest, []) for token in values: if self.use_sets and token.startswith('@'): namespace.sets.append(token[1:]) else: if self.allow_ebuild_paths and token.endswith('.ebuild'): try: repo = getattr(namespace, 'repo', namespace.domain.ebuild_repos_raw) except AttributeError: raise argparse.ArgumentTypeError( 'repo or domain must be defined in the namespace') if not os.path.exists(token): raise argparse.ArgumentError(self, f"nonexistent ebuild: {token!r}") elif not os.path.isfile(token): raise argparse.ArgumentError(self, f"invalid ebuild: {token!r}") if self.allow_external_repos and token not in repo: repo_root_dir = os.path.abspath( pjoin(token, os.pardir, os.pardir, os.pardir)) try: with suppress_logging(): repo = namespace.domain.add_repo( repo_root_dir, config=namespace.config) except repo_errors.RepoError as e: raise argparse.ArgumentError(self, f"{token!r} -- {e}") try: restriction = repo.path_restrict(token) except ValueError as e: raise argparse.ArgumentError(self, e) else: try: restriction = parserestrict.parse_match(token) except parserestrict.ParseError as e: parser.error(e) super().__call__( parser, namespace, (token, restriction), option_string=option_string)
def find_repo(self, path, config, configure=False): """Find and add an external repo to the domain given a path.""" path = os.path.abspath(path) with suppress_logging(): while (parent := os.path.dirname(path)) != path: try: return self.add_repo(path, config=config, configure=configure) except repo_errors.InvalidRepo: path = parent
def find_repo(self, path, config, configure=True): """Find and add an external repo to the domain given a path.""" repo = None path = os.path.abspath(path) with suppress_logging(): while path != self.root: try: repo = self.add_repo(path, config=config, configure=configure) break except repo_errors.InitializationError: path = os.path.dirname(path) return repo
def _setup_repos(namespace, attr): repo = namespace.selected_repo namespace.cwd = os.getcwd() # TODO: move this to StoreRepoObject if repo is None: repo = namespace.domain.all_ebuild_repos_raw # try to add the current working directory as an external repo if namespace.cwd not in repo and not namespace.targets: path = namespace.cwd with suppress_logging(): while path != namespace.domain.root: try: repo = namespace.domain.add_repo(path, config=namespace.config) break except repo_errors.InitializationError: path = os.path.dirname(path) namespace.repo = repo
def _setup_repos(namespace, attr): repo = namespace.selected_repo namespace.cwd = os.getcwd() # TODO: move this to StoreRepoObject if repo is None: repo = namespace.domain.all_ebuild_repos_raw # try to add the current working directory as an external repo if namespace.cwd not in repo and not namespace.targets: path = namespace.cwd with suppress_logging(): while path != namespace.domain.root: try: repo = namespace.domain.add_repo( path, config=namespace.config) break except repo_errors.InitializationError: path = os.path.dirname(path) namespace.repo = repo
def main(self): with suppress_logging(): return super().main()
def __call__(self, parser, namespace, values, option_string=None): if self.separator is not None: values = values.split(self.separator) if self.use_sets: setattr(namespace, self.use_sets, []) if isinstance(values, str): values = [values] elif values is not None and len(values) == 1 and values[0] == '-': if not sys.stdin.isatty(): values = [ x.strip() for x in sys.stdin.readlines() if x.strip() != '' ] # reassign stdin to allow interactivity (currently only works for unix) sys.stdin = open('/dev/tty') else: raise argparse.ArgumentError( self, "'-' is only valid when piping data in") # override default empty tuple value to appendable list if values: setattr(namespace, self.dest, []) for token in values: if self.use_sets and token.startswith('@'): namespace.sets.append(token[1:]) else: if self.allow_ebuild_paths and token.endswith('.ebuild'): try: repo = getattr(namespace, 'repo', namespace.domain.ebuild_repos_raw) except AttributeError: raise argparse.ArgumentTypeError( 'repo or domain must be defined in the namespace') if not os.path.exists(token): raise argparse.ArgumentError( self, f"nonexistent ebuild: {token!r}") elif not os.path.isfile(token): raise argparse.ArgumentError( self, f"invalid ebuild: {token!r}") if self.allow_external_repos and token not in repo: repo_root_dir = os.path.abspath( pjoin(token, os.pardir, os.pardir, os.pardir)) try: with suppress_logging(): repo = namespace.domain.add_repo( repo_root_dir, config=namespace.config) except repo_errors.RepoError as e: raise argparse.ArgumentError( self, f"{token!r} -- {e}") try: restriction = repo.path_restrict(token) except ValueError as e: raise argparse.ArgumentError(self, e) else: try: restriction = parserestrict.parse_match(token) except parserestrict.ParseError as e: parser.error(e) super().__call__(parser, namespace, (token, restriction), option_string=option_string)