diff options
Diffstat (limited to 'pym/portage/dbapi/porttree.py')
-rw-r--r-- | pym/portage/dbapi/porttree.py | 179 |
1 files changed, 45 insertions, 134 deletions
diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index c401c4745..8d71b2325 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -11,7 +11,6 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.data:portage_gid,secpass', 'portage.dbapi.dep_expand:dep_expand', 'portage.dep:dep_getkey,match_from_list,use_reduce', - 'portage.env.loaders:KeyValuePairFileLoader', 'portage.package.ebuild.doebuild:doebuild', 'portage.util:ensure_dirs,shlex_split,writemsg,writemsg_level', 'portage.util.listdir:listdir', @@ -20,7 +19,6 @@ portage.proxy.lazyimport.lazyimport(globals(), from portage.cache.cache_errors import CacheError from portage.cache.mappings import Mapping -from portage.const import REPO_NAME_LOC from portage.dbapi import dbapi from portage.exception import PortageException, \ FileNotFound, InvalidDependString, InvalidPackageName @@ -66,7 +64,15 @@ class portdbapi(dbapi): def _categories(self): return self.settings.categories - def __init__(self, _unused_param=None, mysettings=None): + @property + def porttrees(self): + return list(reversed(self.settings.repositories.repoLocationList())) + + @property + def porttree_root(self): + return self.settings.repositories.mainRepoLocation() + + def __init__(self, mysettings=None): """ @param _unused_param: deprecated, use mysettings['PORTDIR'] instead @type _unused_param: None @@ -82,14 +88,8 @@ class portdbapi(dbapi): from portage import settings self.settings = config(clone=settings) - porttree_root = self.settings['PORTDIR'] - - if _unused_param is not None and _unused_param != porttree_root: - warnings.warn("The first parameter of the " + \ - "portage.dbapi.porttree.portdbapi" + \ - " constructor is now unused. " + \ - "mysettings['PORTDIR'] will be used instead.", - DeprecationWarning, stacklevel=2) + self.repositories = self.settings.repositories + self.treemap = self.repositories.treemap # This is strictly for use in aux_get() doebuild calls when metadata # is generated by the depend phase. It's safest to use a clone for @@ -97,7 +97,7 @@ class portdbapi(dbapi): # instance that is passed in. self.doebuild_settings = config(clone=self.settings) self.depcachedir = os.path.realpath(self.settings.depcachedir) - + if os.environ.get("SANDBOX_ON") == "1": # Make api consumers exempt from sandbox violations # when doing metadata cache updates. @@ -107,35 +107,14 @@ class portdbapi(dbapi): os.environ["SANDBOX_WRITE"] = \ ":".join(filter(None, sandbox_write)) - #adding porttress from repositories - porttrees = [os.path.realpath(x) for x in \ - self.settings.repositories.repoLocationList()] - self._missing_repo_names = self.settings.repositories.missing_repo_names - - # Ensure that each repo_name is unique. Later paths override - # earlier ones that correspond to the same name. - self._ignored_repos = self.settings.repositories.ignored_repos - - self._repository_map = {} - for k, v in self.settings.repositories.location_map.items(): - self._repository_map[os.path.realpath(k)] = v - self.treemap = {} - for k, v in self.settings.repositories.treemap.items(): - self.treemap[k] = os.path.realpath(v) - - self.porttrees = porttrees - porttree_root = os.path.realpath( - self.settings.repositories.mainRepoLocation()) - self.porttree_root = porttree_root - - self.eclassdb = eclass_cache.cache(porttree_root) + self.eclassdb = eclass_cache.cache(self.settings.repositories.mainRepoLocation()) # This is used as sanity check for aux_get(). If there is no # root eclass dir, we assume that PORTDIR is invalid or # missing. This check allows aux_get() to detect a missing # portage tree and return early by raising a KeyError. self._have_root_eclass_dir = os.path.isdir( - os.path.join(self.porttree_root, "eclass")) + os.path.join(self.settings.repositories.mainRepoLocation(), "eclass")) self.metadbmodule = self.settings.load_best_module("portdbapi.metadbmodule") @@ -143,102 +122,28 @@ class portdbapi(dbapi): self.xcache = {} self.frozen = 0 + #Create eclass dbs self._repo_info = {} - eclass_dbs = {porttree_root : self.eclassdb} - local_repo_configs = self.settings.repositories.prepos - default_loc_repo_config = None - repo_aliases = {} - if local_repo_configs is not None: - default_loc_repo_config = local_repo_configs.get('DEFAULT') - for repo_name, loc_repo_conf in local_repo_configs.items(): - if loc_repo_conf.aliases is not None: - for alias in loc_repo_conf.aliases: - overridden_alias = repo_aliases.get(alias) - if overridden_alias is not None: - writemsg_level(_("!!! Alias '%s' " \ - "created for '%s' overrides " \ - "'%s' alias in " \ - "'%s'\n") % (alias, repo_name, - overridden_alias, - 'repos.conf'), - level=logging.WARNING, noiselevel=-1) - repo_aliases[alias] = repo_name - - for path in self.porttrees: - if path in self._repo_info: + eclass_dbs = {self.settings.repositories.mainRepoLocation() : self.eclassdb} + for repo in self.repositories: + if repo.location in self._repo_info: continue - repo_name = self._repository_map.get(path) - - loc_repo_conf = None - if local_repo_configs is not None: - if repo_name is not None: - loc_repo_conf = local_repo_configs.get(repo_name) - if loc_repo_conf is None: - loc_repo_conf = default_loc_repo_config - - layout_filename = os.path.join(path, "metadata/layout.conf") - layout_file = KeyValuePairFileLoader(layout_filename, None, None) - layout_data, layout_errors = layout_file.load() - porttrees = [] - - masters = None - if loc_repo_conf is not None and \ - loc_repo_conf.masters is not None: - masters = loc_repo_conf.masters - else: - masters = layout_data.get('masters', '').split() - - for master_name in masters: - master_name = repo_aliases.get(master_name, master_name) - master_path = self.treemap.get(master_name) - if master_path is None: - writemsg_level(_("Unavailable repository '%s' " \ - "referenced by masters entry in '%s'\n") % \ - (master_name, layout_filename), - level=logging.ERROR, noiselevel=-1) - else: - porttrees.append(master_path) - - if not porttrees and path != porttree_root: - # Make PORTDIR the default master, but only if our - # heuristics suggest that it's necessary. - profiles_desc = os.path.join(path, 'profiles', 'profiles.desc') - eclass_dir = os.path.join(path, 'eclass') - if not os.path.isfile(profiles_desc) or \ - not os.path.isdir(eclass_dir): - porttrees.append(porttree_root) - - porttrees.append(path) - - if loc_repo_conf is not None and \ - loc_repo_conf.eclass_overrides is not None: - for other_name in loc_repo_conf.eclass_overrides: - other_path = self.treemap.get(other_name) - if other_path is None: - writemsg_level(_("Unavailable repository '%s' " \ - "referenced by eclass-overrides entry in " \ - "'%s'\n") % (other_name, - 'repos.conf'), - level=logging.ERROR, noiselevel=-1) - continue - porttrees.append(other_path) - eclass_db = None - for porttree in porttrees: - tree_db = eclass_dbs.get(porttree) + for eclass_location in repo.eclass_locations: + tree_db = eclass_dbs.get(eclass_location) if tree_db is None: - tree_db = eclass_cache.cache(porttree) - eclass_dbs[porttree] = tree_db + tree_db = eclass_cache.cache(eclass_location) + eclass_dbs[eclass_location] = tree_db if eclass_db is None: eclass_db = tree_db.copy() else: eclass_db.append(tree_db) - self._repo_info[path] = _repo_info(repo_name, path, eclass_db) + self._repo_info[repo.location] = _repo_info(repo.name, repo.location, eclass_db) #Keep a list of repo names, sorted by priority (highest priority first). - self._ordered_repo_name_list = tuple(self._repo_info[path].name for path in reversed(self.porttrees)) + self._ordered_repo_name_list = tuple(reversed(self.repositories.prepos_order)) self.auxdbmodule = self.settings.load_best_module("portdbapi.auxdbmodule") self.auxdb = {} @@ -261,7 +166,7 @@ class portdbapi(dbapi): filtered_auxdbkeys.sort() from portage.cache import metadata_overlay, volatile if not depcachedir_w_ok: - for x in self.porttrees: + for x in reversed(self.repositories.repoLocationList()): db_ro = self.auxdbmodule(self.depcachedir, x, filtered_auxdbkeys, gid=portage_gid, readonly=True) self.auxdb[x] = metadata_overlay.database( @@ -269,7 +174,7 @@ class portdbapi(dbapi): gid=portage_gid, db_rw=volatile.database, db_ro=db_ro) else: - for x in self.porttrees: + for x in reversed(self.repositories.repoLocationList()): if x in self.auxdb: continue # location, label, auxdbkeys @@ -278,7 +183,7 @@ class portdbapi(dbapi): if self.auxdbmodule is metadata_overlay.database: self.auxdb[x].db_ro.ec = self._repo_info[x].eclass_db if "metadata-transfer" not in self.settings.features: - for x in self.porttrees: + for x in reversed(self.repositories.repoLocationList()): if x in self._pregen_auxdb: continue if os.path.isdir(os.path.join(x, "metadata", "cache")): @@ -324,9 +229,7 @@ class portdbapi(dbapi): x.sync() def findLicensePath(self, license_name): - mytrees = self.porttrees[:] - mytrees.reverse() - for x in mytrees: + for x in reversed(self.repositories.repoLocationList()): license_path = os.path.join(x, "licenses", license_name) if os.access(license_path, os.R_OK): return license_path @@ -355,7 +258,10 @@ class portdbapi(dbapi): if the path does not correspond a known repository @rtype: String or None """ - return self._repository_map.get(canonical_repo_path) + try: + return self.repositories.get_name_for_location(canonical_repo_path) + except KeyError: + return None def getRepositories(self): """ @@ -369,7 +275,14 @@ class portdbapi(dbapi): """ Returns a list of repository paths that lack profiles/repo_name. """ - return self._missing_repo_names + return self.settings.repositories.missing_repo_names + + def getIgnoredRepos(self): + """ + Returns a list of repository paths that have been ignored, because + another repo with the same name exists. + """ + return self.settings.repositories.ignored_repos def findname2(self, mycpv, mytree=None, myrepo = None): """ @@ -402,8 +315,7 @@ class portdbapi(dbapi): if mytree: mytrees = [mytree] else: - mytrees = self.porttrees[:] - mytrees.reverse() + mytrees = reversed(self.repositories.repoLocationList()) relative_path = mysplit[0] + _os.sep + psplit[0] + _os.sep + \ mysplit[1] + ".ebuild" @@ -590,8 +502,7 @@ class portdbapi(dbapi): mydata = proc.metadata # do we have a origin repository name for the current package - mydata["repository"] = self._repository_map.get(mylocation, "") - + mydata["repository"] = self.repositories.get_name_for_location(mylocation) mydata["INHERITED"] = ' '.join(mydata.get("_eclasses_", [])) mydata["_mtime_"] = st[stat.ST_MTIME] @@ -770,7 +681,7 @@ class portdbapi(dbapi): if categories is None: categories = self.settings.categories if trees is None: - trees = self.porttrees + trees = reversed(self.repositories.repoLocationList()) for x in categories: for oroot in trees: for y in listdir(oroot+"/"+x, EmptyOnError=1, ignorecvs=1, dirsonly=1): @@ -803,7 +714,7 @@ class portdbapi(dbapi): # assume it's iterable mytrees = mytree else: - mytrees = self.porttrees + mytrees = reversed(self.repositories.repoLocationList()) for oroot in mytrees: try: file_list = os.listdir(os.path.join(oroot, mycp)) @@ -899,7 +810,7 @@ class portdbapi(dbapi): mylist = self.cp_list(mykey) else: mylist = match_from_list(mydep, self.cp_list(mykey, - mytree=self._repository_map.get(mydep.repo))) + mytree=self.repositories.get_location_for_name(mydep.repo))) myval = "" settings = self.settings local_config = settings.local_config |