summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gmail.com>2011-08-31 16:42:34 -0700
committerZac Medico <zmedico@gentoo.org>2011-09-12 14:23:09 -0700
commit53860ffa675b0cf1930589ff9fa15b5ffaa2cf75 (patch)
tree284247fc334fdad4d49346afe82eafba9c69b0a5
parent9116d2b8a7b553e4d445f0d9329a28aa54dfd1ef (diff)
downloadportage-53860ffa675b0cf1930589ff9fa15b5ffaa2cf75.tar.gz
portage-53860ffa675b0cf1930589ff9fa15b5ffaa2cf75.tar.bz2
portage-53860ffa675b0cf1930589ff9fa15b5ffaa2cf75.zip
refactoring; unhide part of the parsing functionality
-rw-r--r--pym/portage/repository/config.py198
1 files changed, 98 insertions, 100 deletions
diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py
index a12bd7bc5..020297ce9 100644
--- a/pym/portage/repository/config.py
+++ b/pym/portage/repository/config.py
@@ -179,107 +179,101 @@ class RepoConfig(object):
class RepoConfigLoader(object):
"""Loads and store config of several repositories, loaded from PORTDIR_OVERLAY or repos.conf"""
- def __init__(self, paths, settings):
- """Load config from files in paths"""
- def parse(paths, prepos, ignored_map, ignored_location_map):
- """Parse files in paths to load config"""
- parser = SafeConfigParser()
- try:
- parser.read(paths)
- except ParsingError as e:
- writemsg(_("!!! Error while reading repo config file: %s\n") % e, noiselevel=-1)
- prepos['DEFAULT'] = RepoConfig("DEFAULT", parser.defaults())
- for sname in parser.sections():
- optdict = {}
- for oname in parser.options(sname):
- optdict[oname] = parser.get(sname, oname)
-
- repo = RepoConfig(sname, optdict)
- if repo.location and not os.path.exists(repo.location):
- writemsg(_("!!! Invalid repos.conf entry '%s'"
- " (not a dir): '%s'\n") % (sname, repo.location), noiselevel=-1)
- continue
- if repo.name in prepos:
- old_location = prepos[repo.name].location
- if old_location is not None and repo.location is not None and old_location != repo.location:
- ignored_map.setdefault(repo.name, []).append(old_location)
- ignored_location_map[old_location] = repo.name
- prepos[repo.name].update(repo)
- else:
- prepos[repo.name] = repo
-
- def add_overlays(portdir, portdir_overlay, prepos, ignored_map, ignored_location_map):
- """Add overlays in PORTDIR_OVERLAY as repositories"""
- overlays = []
- if portdir:
- portdir = normalize_path(portdir)
- overlays.append(portdir)
- port_ov = [normalize_path(i) for i in shlex_split(portdir_overlay)]
- overlays.extend(port_ov)
- default_repo_opts = {}
- if prepos['DEFAULT'].aliases is not None:
- default_repo_opts['aliases'] = \
- ' '.join(prepos['DEFAULT'].aliases)
- if prepos['DEFAULT'].eclass_overrides is not None:
- default_repo_opts['eclass-overrides'] = \
- ' '.join(prepos['DEFAULT'].eclass_overrides)
- if prepos['DEFAULT'].masters is not None:
- default_repo_opts['masters'] = \
- ' '.join(prepos['DEFAULT'].masters)
- if overlays:
- #overlay priority is negative because we want them to be looked before any other repo
- base_priority = 0
- for ov in overlays:
- if os.path.isdir(ov):
- repo_opts = default_repo_opts.copy()
- repo_opts['location'] = ov
- repo = RepoConfig(None, repo_opts)
- repo_conf_opts = prepos.get(repo.name)
- if repo_conf_opts is not None:
- if repo_conf_opts.aliases is not None:
- repo_opts['aliases'] = \
- ' '.join(repo_conf_opts.aliases)
- if repo_conf_opts.eclass_overrides is not None:
- repo_opts['eclass-overrides'] = \
- ' '.join(repo_conf_opts.eclass_overrides)
- if repo_conf_opts.masters is not None:
- repo_opts['masters'] = \
- ' '.join(repo_conf_opts.masters)
- repo = RepoConfig(repo.name, repo_opts)
- if repo.name in prepos:
- old_location = prepos[repo.name].location
- if old_location is not None and old_location != repo.location:
- ignored_map.setdefault(repo.name, []).append(old_location)
- ignored_location_map[old_location] = repo.name
- if old_location == portdir:
- portdir = repo.user_location
- prepos[repo.name].update(repo)
- repo = prepos[repo.name]
- else:
- prepos[repo.name] = repo
-
- if ov == portdir and portdir not in port_ov:
- repo.priority = -1000
- else:
- repo.priority = base_priority
- base_priority += 1
+ @staticmethod
+ def _add_overlays(portdir, portdir_overlay, prepos, ignored_map, ignored_location_map):
+ """Add overlays in PORTDIR_OVERLAY as repositories"""
+ overlays = []
+ if portdir:
+ portdir = normalize_path(portdir)
+ overlays.append(portdir)
+ port_ov = [normalize_path(i) for i in shlex_split(portdir_overlay)]
+ overlays.extend(port_ov)
+ default_repo_opts = {}
+ if prepos['DEFAULT'].aliases is not None:
+ default_repo_opts['aliases'] = \
+ ' '.join(prepos['DEFAULT'].aliases)
+ if prepos['DEFAULT'].eclass_overrides is not None:
+ default_repo_opts['eclass-overrides'] = \
+ ' '.join(prepos['DEFAULT'].eclass_overrides)
+ if prepos['DEFAULT'].masters is not None:
+ default_repo_opts['masters'] = \
+ ' '.join(prepos['DEFAULT'].masters)
+ if overlays:
+ #overlay priority is negative because we want them to be looked before any other repo
+ base_priority = 0
+ for ov in overlays:
+ if os.path.isdir(ov):
+ repo_opts = default_repo_opts.copy()
+ repo_opts['location'] = ov
+ repo = RepoConfig(None, repo_opts)
+ repo_conf_opts = prepos.get(repo.name)
+ if repo_conf_opts is not None:
+ if repo_conf_opts.aliases is not None:
+ repo_opts['aliases'] = \
+ ' '.join(repo_conf_opts.aliases)
+ if repo_conf_opts.eclass_overrides is not None:
+ repo_opts['eclass-overrides'] = \
+ ' '.join(repo_conf_opts.eclass_overrides)
+ if repo_conf_opts.masters is not None:
+ repo_opts['masters'] = \
+ ' '.join(repo_conf_opts.masters)
+ repo = RepoConfig(repo.name, repo_opts)
+ if repo.name in prepos:
+ old_location = prepos[repo.name].location
+ if old_location is not None and old_location != repo.location:
+ ignored_map.setdefault(repo.name, []).append(old_location)
+ ignored_location_map[old_location] = repo.name
+ if old_location == portdir:
+ portdir = repo.user_location
+ prepos[repo.name].update(repo)
+ repo = prepos[repo.name]
+ else:
+ prepos[repo.name] = repo
+ if ov == portdir and portdir not in port_ov:
+ repo.priority = -1000
else:
- writemsg(_("!!! Invalid PORTDIR_OVERLAY"
- " (not a dir): '%s'\n") % ov, noiselevel=-1)
+ repo.priority = base_priority
+ base_priority += 1
+
+ else:
+ writemsg(_("!!! Invalid PORTDIR_OVERLAY"
+ " (not a dir): '%s'\n") % ov, noiselevel=-1)
- return portdir
+ return portdir
- def repo_priority(r):
- """
- Key funtion for comparing repositories by priority.
- None is equal priority zero.
- """
- x = prepos[r].priority
- if x is None:
- return 0
- return x
+ @staticmethod
+ def _parse(paths, prepos, ignored_map, ignored_location_map):
+ """Parse files in paths to load config"""
+ parser = SafeConfigParser()
+ try:
+ parser.read(paths)
+ except ParsingError as e:
+ writemsg(_("!!! Error while reading repo config file: %s\n") % e, noiselevel=-1)
+ prepos['DEFAULT'] = RepoConfig("DEFAULT", parser.defaults())
+ for sname in parser.sections():
+ optdict = {}
+ for oname in parser.options(sname):
+ optdict[oname] = parser.get(sname, oname)
+
+ repo = RepoConfig(sname, optdict)
+ if repo.location and not os.path.exists(repo.location):
+ writemsg(_("!!! Invalid repos.conf entry '%s'"
+ " (not a dir): '%s'\n") % (sname, repo.location), noiselevel=-1)
+ continue
+
+ if repo.name in prepos:
+ old_location = prepos[repo.name].location
+ if old_location is not None and repo.location is not None and old_location != repo.location:
+ ignored_map.setdefault(repo.name, []).append(old_location)
+ ignored_location_map[old_location] = repo.name
+ prepos[repo.name].update(repo)
+ else:
+ prepos[repo.name] = repo
+
+ def __init__(self, paths, settings):
+ """Load config from files in paths"""
prepos = {}
location_map = {}
@@ -289,10 +283,12 @@ class RepoConfigLoader(object):
portdir = settings.get('PORTDIR', '')
portdir_overlay = settings.get('PORTDIR_OVERLAY', '')
- parse(paths, prepos, ignored_map, ignored_location_map)
+
+ self._parse(paths, prepos, ignored_map, ignored_location_map)
+
# If PORTDIR_OVERLAY contains a repo with the same repo_name as
# PORTDIR, then PORTDIR is overridden.
- portdir = add_overlays(portdir, portdir_overlay, prepos,
+ portdir = self._add_overlays(portdir, portdir_overlay, prepos,
ignored_map, ignored_location_map)
if portdir and portdir.strip():
portdir = os.path.realpath(portdir)
@@ -352,9 +348,11 @@ class RepoConfigLoader(object):
# filter duplicates from aliases, by only including
# items where repo.name == key
- prepos_order = [repo.name for key, repo in prepos.items() \
+
+ prepos_order = sorted(prepos.items(), key=lambda r:r[1].priority or 0)
+
+ prepos_order = [repo.name for (key, repo) in prepos_order
if repo.name == key and repo.location is not None]
- prepos_order.sort(key=repo_priority)
if portdir in location_map:
portdir_repo = prepos[location_map[portdir]]