def dynamic_getattr_dict(self, attr): functor = self._get_attr.get(attr) if functor is None: raise AttributeError(self, attr) try: val = functor(self) object.__setattr__(self, attr, val) return val except errors.MetadataException as e: if e.attr == attr: raise raise errors.MetadataException(self, attr, e.error, e.verbose) from e except (errors.PackageError, UnicodeDecodeError) as e: raise errors.MetadataException(self, attr, str(e)) from e except PermissionError as e: raise base_errors.PermissionDenied(self.path, write=False) from e
def load_make_conf(vars_dict, path, allow_sourcing=False, required=True, allow_recurse=True, incrementals=False): """parse make.conf files Args: vars_dict (dict): dictionary to add parsed variables to path (str): path to the make.conf which can be a regular file or directory, if a directory is passed all the non-hidden files within that directory are parsed in alphabetical order. """ sourcing_command = 'source' if allow_sourcing else None if allow_recurse: files = sorted_scan(os.path.realpath(path), follow_symlinks=True, nonexistent=True, hidden=False, backup=False) else: files = (path, ) for fp in files: try: new_vars = read_bash_dict(fp, vars_dict=vars_dict, sourcing_command=sourcing_command) except PermissionError as e: raise base_errors.PermissionDenied(fp, write=False) from e except EnvironmentError as e: if e.errno != errno.ENOENT or required: raise config_errors.ParsingError(f"parsing {fp!r}", exception=e) from e return if incrementals: for key in econst.incrementals: if key in vars_dict and key in new_vars: new_vars[key] = f"{vars_dict[key]} {new_vars[key]}" # quirk of read_bash_dict; it returns only what was mutated. vars_dict.update(new_vars)
def load_repos_conf(cls, path): """parse repos.conf files Args: path (str): path to the repos.conf which can be a regular file or directory, if a directory is passed all the non-hidden files within that directory are parsed in alphabetical order. Returns: dict: global repo settings dict: repo settings """ main_defaults = {} repos = {} parser = ParseConfig() for fp in sorted_scan(os.path.realpath(path), follow_symlinks=True, nonexistent=True, hidden=False, backup=False): try: with open(fp) as f: defaults, repo_confs = parser.parse_file(f) except PermissionError as e: raise base_errors.PermissionDenied(fp, write=False) from e except EnvironmentError as e: raise config_errors.ParsingError(f"parsing {fp!r}", exception=e) from e except configparser.Error as e: raise config_errors.ParsingError(f"repos.conf: {fp!r}", exception=e) from e if defaults and main_defaults: logger.warning( f"repos.conf: parsing {fp!r}: overriding DEFAULT section") main_defaults.update(defaults) for name, repo_conf in repo_confs.items(): if name in repos: logger.warning( f"repos.conf: parsing {fp!r}: overriding {name!r} repo" ) # ignore repo if location is unset location = repo_conf.get('location', None) if location is None: logger.warning( f"repos.conf: parsing {fp!r}: " f"{name!r} repo missing location setting, ignoring repo" ) continue repo_conf['location'] = os.path.abspath(location) # repo type defaults to ebuild for compat with portage repo_type = repo_conf.get('repo-type', 'ebuild-v1') try: repo_conf['repo-type'] = cls._supported_repo_types[ repo_type] except KeyError: logger.warning( f"repos.conf: parsing {fp!r}: " f"{name!r} repo has unsupported repo-type {repo_type!r}, " "ignoring repo") continue # Priority defaults to zero if unset or invalid for ebuild repos # while binpkg repos have the lowest priority by default. priority = repo_conf.get('priority', None) if priority is None: if repo_type.startswith('binpkg'): priority = -10000 else: priority = 0 try: priority = int(priority) except ValueError: logger.warning( f"repos.conf: parsing {fp!r}: {name!r} repo has invalid priority " f"setting: {priority!r} (defaulting to 0)") priority = 0 finally: repo_conf['priority'] = priority # register repo repos[name] = repo_conf if repos: # the default repo is gentoo if unset and gentoo exists default_repo = main_defaults.get('main-repo', 'gentoo') if default_repo not in repos: raise config_errors.UserConfigError( f"repos.conf: default repo {default_repo!r} is undefined or invalid" ) if 'main-repo' not in main_defaults: main_defaults['main-repo'] = default_repo # the default repo has a low priority if unset or zero if repos[default_repo]['priority'] == 0: repos[default_repo]['priority'] = -1000 # sort repos via priority, in this case high values map to high priorities repos = OrderedDict((k, v) for k, v in sorted( repos.items(), key=lambda d: d[1]['priority'], reverse=True)) return main_defaults, repos