def __init__(self, paths, settings): """Load config from files in paths""" # Defaults for value interpolation. parser_defaults = { "EPREFIX" : settings["EPREFIX"], "EROOT" : settings["EROOT"], "PORTAGE_CONFIGROOT" : settings["PORTAGE_CONFIGROOT"], "ROOT" : settings["ROOT"], } try: parser = self._parse(paths, parser_defaults) except ConfigParserError as e: writemsg( _("!!! Error while reading binrepo config file: %s\n") % e, noiselevel=-1) parser = SafeConfigParser(defaults=parser_defaults) repos = [] sync_uris = [] for section_name in parser.sections(): repo_data = dict(parser[section_name].items()) repo_data['name'] = section_name repo = BinRepoConfig(repo_data) if repo.sync_uri is None: writemsg(_("!!! Missing sync-uri setting for binrepo %s\n") % (repo.name,), noiselevel=-1) continue sync_uri = self._normalize_uri(repo.sync_uri) sync_uris.append(sync_uri) repo.sync_uri = sync_uri if repo.priority is not None: try: repo.priority = int(repo.priority) except ValueError: repo.priority = None repos.append(repo) sync_uris = set(sync_uris) current_priority = 0 for sync_uri in reversed(settings.get("PORTAGE_BINHOST", "").split()): sync_uri = self._normalize_uri(sync_uri) if sync_uri not in sync_uris: current_priority += 1 sync_uris.add(sync_uri) repos.append(BinRepoConfig({ 'name-fallback': self._digest_uri(sync_uri), 'name': None, 'priority': current_priority, 'sync-uri': sync_uri, })) self._data = OrderedDict((repo.name or repo.name_fallback, repo) for repo in sorted(repos, key=lambda repo: (repo.priority or 0, repo.name or repo.name_fallback)))
def _parse(paths, prepos, local_config, default_opts): """Parse files in paths to load config""" parser = SafeConfigParser(defaults=default_opts) recursive_paths = [] for p in paths: if isinstance(p, basestring): recursive_paths.extend(_recursive_file_list(p)) else: recursive_paths.append(p) read_configs(parser, recursive_paths) prepos['DEFAULT'] = RepoConfig("DEFAULT", parser.defaults(), local_config=local_config) for sname in parser.sections(): optdict = {} for oname in parser.options(sname): optdict[oname] = parser.get(sname, oname) repo = RepoConfig(sname, optdict, local_config=local_config) for o in portage.sync.module_specific_options(repo): if parser.has_option(sname, o): repo.set_module_specific_opt(o, parser.get(sname, o)) # Perform repos.conf sync variable validation portage.sync.validate_config(repo, logging) # For backward compatibility with locations set via PORTDIR and # PORTDIR_OVERLAY, delay validation of the location and repo.name # until after PORTDIR and PORTDIR_OVERLAY have been processed. prepos[sname] = repo
def _parse(paths, prepos, local_config, default_opts): """Parse files in paths to load config""" parser = SafeConfigParser(defaults=default_opts) recursive_paths = [] for p in paths: if isinstance(p, basestring): recursive_paths.extend(_recursive_file_list(p)) else: recursive_paths.append(p) read_configs(parser, recursive_paths) prepos['DEFAULT'] = RepoConfig("DEFAULT", parser.defaults(), local_config=local_config) for sname in parser.sections(): optdict = {} for oname in parser.options(sname): optdict[oname] = parser.get(sname, oname) repo = RepoConfig(sname, optdict, local_config=local_config) for o in portage.sync.module_specific_options(repo): if parser.has_option(sname, o): repo.set_module_specific_opt(o, parser.get(sname, o)) # Perform repos.conf sync variable validation portage.sync.validate_config(repo, logging) # For backward compatibility with locations set via PORTDIR and # PORTDIR_OVERLAY, delay validation of the location and repo.name # until after PORTDIR and PORTDIR_OVERLAY have been processed. prepos[sname] = repo
def _parse(paths, defaults): parser = SafeConfigParser(defaults=defaults) recursive_paths = [] for p in paths: if isinstance(p, str): recursive_paths.extend(_recursive_file_list(p)) else: recursive_paths.append(p) read_configs(parser, recursive_paths) return parser
def __init__(self, paths, settings, trees): self._parser = SafeConfigParser( defaults={ "EPREFIX": settings["EPREFIX"], "EROOT": settings["EROOT"], "PORTAGE_CONFIGROOT": settings["PORTAGE_CONFIGROOT"], "ROOT": settings["ROOT"], }) if _ENABLE_SET_CONFIG: read_configs(self._parser, paths) else: self._create_default_config() self.errors = [] self.psets = {} self.trees = trees self.settings = settings self._parsed = False self.active = []
#!/bin/env python3 import sys import collections from portage.util.configparser import (read_configs, SafeConfigParser) p = SafeConfigParser({}, collections.defaultdict) read_configs(p, sys.argv[1:]) first = True for sect in sorted(p.sections()): if first: first = False else: print() print("[{}]".format(sect)) for itm in sorted(p.items(sect)): print("{} = {}".format(itm[0], itm[1]))