From 4fcabea01d5664bd213db35f6894ec9e4308835d Mon Sep 17 00:00:00 2001 From: Sebastian Luther Date: Fri, 27 Aug 2010 09:33:40 +0200 Subject: config: Add MaskManager --- pym/portage/package/ebuild/_config/MaskManager.py | 69 +++++++++++++++++++++++ pym/portage/package/ebuild/config.py | 48 ++-------------- 2 files changed, 75 insertions(+), 42 deletions(-) create mode 100644 pym/portage/package/ebuild/_config/MaskManager.py diff --git a/pym/portage/package/ebuild/_config/MaskManager.py b/pym/portage/package/ebuild/_config/MaskManager.py new file mode 100644 index 000000000..7a5fc5e17 --- /dev/null +++ b/pym/portage/package/ebuild/_config/MaskManager.py @@ -0,0 +1,69 @@ +# Copyright 2010 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +__all__ = ( + 'MaskManager', +) + +from portage import os +from portage.dep import ExtendedAtomDict, match_from_list +from portage.util import grabfile_package, stack_lists +from portage.versions import cpv_getkey + +class MaskManager(object): + + def __init__(self, pmask_locations, abs_user_config, user_config=True): + self._punmaskdict = ExtendedAtomDict(list) + self._pmaskdict = ExtendedAtomDict(list) + + pkgmasklines = [] + pkgunmasklines = [] + for x in pmask_locations: + pkgmasklines.append(grabfile_package( + os.path.join(x, "package.mask"), recursive=1)) + pkgunmasklines.append(grabfile_package( + os.path.join(x, "package.unmask"), recursive=1)) + + if user_config: + pkgmasklines.append(grabfile_package( + os.path.join(abs_user_config, "package.mask"), recursive=1, allow_wildcard=True)) + pkgunmasklines.append(grabfile_package( + os.path.join(abs_user_config, "package.unmask"), recursive=1, allow_wildcard=True)) + + pkgmasklines = stack_lists(pkgmasklines, incremental=1) + pkgunmasklines = stack_lists(pkgunmasklines, incremental=1) + + for x in pkgmasklines: + self._pmaskdict.setdefault(x.cp, []).append(x) + + for x in pkgunmasklines: + self._punmaskdict.setdefault(x.cp, []).append(x) + + def getMaskAtom(self, cpv, slot): + """ + Take a package and return a matching package.mask atom, or None if no + such atom exists or it has been cancelled by package.unmask. PROVIDE + is not checked, so atoms will not be found for old-style virtuals. + + @param cpv: The package name + @type cpv: String + @param slot: The package's slot + @type slot: String + @rtype: String + @return: An matching atom string or None if one is not found. + """ + + cp = cpv_getkey(cpv) + mask_atoms = self._pmaskdict.get(cp) + if mask_atoms: + pkg_list = ["%s:%s" % (cpv, slot)] + unmask_atoms = self._punmaskdict.get(cp) + for x in mask_atoms: + if not match_from_list(x, pkg_list): + continue + if unmask_atoms: + for y in unmask_atoms: + if match_from_list(y, pkg_list): + return None + return x + return None diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index 122a7f6ed..afb4641c9 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -49,6 +49,7 @@ from portage.versions import catpkgsplit, catsplit, cpv_getkey from portage.package.ebuild._config.features_set import features_set from portage.package.ebuild._config.LicenseManager import LicenseManager from portage.package.ebuild._config.UseManager import UseManager +from portage.package.ebuild._config.MaskManager import MaskManager from portage.package.ebuild._config.helper import ordered_by_atom_specificity, prune_incremental if sys.hexversion >= 0x3000000: @@ -394,6 +395,7 @@ class config(object): self._pkeywords_list = clone._pkeywords_list self._p_accept_keywords = clone._p_accept_keywords self._use_manager = clone._use_manager + self._mask_manager = clone._mask_manager self.modules = copy.deepcopy(clone.modules) self.virtuals = copy.deepcopy(clone.virtuals) @@ -420,8 +422,6 @@ class config(object): self._use_expand_dict = copy.deepcopy(clone._use_expand_dict) self.backupenv = self.configdict["backupenv"] self.pkeywordsdict = copy.deepcopy(clone.pkeywordsdict) - self.pmaskdict = copy.deepcopy(clone.pmaskdict) - self.punmaskdict = copy.deepcopy(clone.punmaskdict) self.prevmaskdict = copy.deepcopy(clone.prevmaskdict) self.pprovideddict = copy.deepcopy(clone.pprovideddict) self.features = features_set(self) @@ -804,7 +804,6 @@ class config(object): self.pkeywordsdict = portage.dep.ExtendedAtomDict(dict) self._ppropertiesdict = portage.dep.ExtendedAtomDict(dict) self._penvdict = portage.dep.ExtendedAtomDict(dict) - self.punmaskdict = portage.dep.ExtendedAtomDict(list) # locations for "categories" and "arch.list" files locations = [os.path.join(self["PORTDIR"], "profiles")] @@ -837,15 +836,6 @@ class config(object): pmask_locations.extend(overlay_profiles) - # package.mask and package.unmask - pkgmasklines = [] - pkgunmasklines = [] - for x in pmask_locations: - pkgmasklines.append(grabfile_package( - os.path.join(x, "package.mask"), recursive=1)) - pkgunmasklines.append(grabfile_package( - os.path.join(x, "package.unmask"), recursive=1)) - #Read all USE related files from profiles and optionally from user config. self._use_manager = UseManager(self.profiles, abs_user_config, user_config=local_config) #Initialize all USE related variables we track ourselves. @@ -862,14 +852,12 @@ class config(object): self._license_manager.extract_global_changes( \ self.configdict["conf"].get("ACCEPT_LICENSE", "")) + #Read package.mask and package.unmask from profiles and optionally from user config + self._mask_manager = MaskManager(pmask_locations, abs_user_config, user_config=local_config) + if local_config: locations.append(abs_user_config) - pkgmasklines.append(grabfile_package( - os.path.join(abs_user_config, "package.mask"), recursive=1, allow_wildcard=True)) - pkgunmasklines.append(grabfile_package( - os.path.join(abs_user_config, "package.unmask"), recursive=1, allow_wildcard=True)) - # package.accept_keywords and package.keywords pkgdict = grabdict_package( os.path.join(abs_user_config, "package.keywords"), @@ -972,16 +960,6 @@ class config(object): archlist = stack_lists(archlist, incremental=1) self.configdict["conf"]["PORTAGE_ARCHLIST"] = " ".join(archlist) - pkgmasklines = stack_lists(pkgmasklines, incremental=1) - pkgunmasklines = stack_lists(pkgunmasklines, incremental=1) - - self.pmaskdict = portage.dep.ExtendedAtomDict(list) - for x in pkgmasklines: - self.pmaskdict.setdefault(x.cp, []).append(x) - - for x in pkgunmasklines: - self.punmaskdict.setdefault(x.cp, []).append(x) - pkgprovidedlines = [grabfile(os.path.join(x, "package.provided"), recursive=1) for x in self.profiles] pkgprovidedlines = stack_lists(pkgprovidedlines, incremental=1) has_invalid_data = False @@ -1715,21 +1693,7 @@ class config(object): @rtype: String @return: An matching atom string or None if one is not found. """ - - cp = cpv_getkey(cpv) - mask_atoms = self.pmaskdict.get(cp) - if mask_atoms: - pkg_list = ["%s:%s" % (cpv, metadata["SLOT"])] - unmask_atoms = self.punmaskdict.get(cp) - for x in mask_atoms: - if not match_from_list(x, pkg_list): - continue - if unmask_atoms: - for y in unmask_atoms: - if match_from_list(y, pkg_list): - return None - return x - return None + return self._mask_manager.getMaskAtom(cpv, metadata["SLOT"]) def _getProfileMaskAtom(self, cpv, metadata): """ -- cgit v1.2.3-1-g7c22