add a new function to MaskManager that optimizies getting any raw mask atoms
authorBrian Dolbec <brian.dolbec@gmail.com>
Sun, 30 Jan 2011 03:22:58 +0000 (19:22 -0800)
committerZac Medico <zmedico@gentoo.org>
Sun, 30 Jan 2011 09:11:58 +0000 (01:11 -0800)
pym/_emerge/Package.py
pym/portage/package/ebuild/_config/MaskManager.py
pym/portage/package/ebuild/config.py

index 96c76b965916af56534fe8313b463ecaab75769f..ae9e8f293f57e0b8bacf844497c9eb5aa7bfdd03 100644 (file)
@@ -239,7 +239,7 @@ class Package(Task):
 
        def accepted_keyword(self):
                """returns the keyword used from the ebuild's KEYWORDS string"""
-               
+
                keywords = set(self.metadata.get('KEYWORDS').split())
                accept_keywords = set(self.root_config.settings['ACCEPT_KEYWORDS'].split())
                used_keyword = list(set.intersection(keywords, accept_keywords))
@@ -250,31 +250,14 @@ class Package(Task):
                        writemsg_level( "_emerge.output.resolver.Display(), too many keywords recieved for pkg: %s, %s"
                                        % (pkg.cpv, used_keyword))
                        used_keyword = used_keyword[0]
-               #print "pmaskdict", self.root_config.settings.pmaskdict
                return used_keyword
 
        def isHardMasked(self):
-               """returns a bool if the cpv is in the list of 
+               """returns a bool if the cpv is in the list of
                expanded pmaskdict[cp] availble ebuilds"""
-               try:
-                       # returns a list of mask atoms
-                       pmask = self.root_config.settings.pmaskdict[self.cp]
-               except KeyError:
-                       pmask = []
-               if pmask:
-                       # narrow pmask atoms down to the relevant repo
-                       n = [x for x in pmask if x.split('::')[-1] in [self.repo]]
-                       # hopefully it is down to only 1 mask atom
-                       #print "n =", n
-                       #count = 0
-                       hardmasked = set()
-                       for x in n:
-                               #expand the atom to matching available ebuilds
-                               hardmasked.update(self.root_config.trees['porttree'].dbapi.xmatch("match-all",x))
-                               #count += 1
-                       #print "for x in n: loop count =", count, hardmasked
-                       return self.cpv in hardmasked
-               return False
+               pmask = self.root_config.settings._getRawMaskAtom(self.cpv, self.metadata)
+               print "pmask =", pmask
+               return pmask is not None
 
 
        def _metadata_exception(self, k, e):
@@ -448,7 +431,7 @@ class Package(Task):
                                        not self._iuse_implicit_match(flag):
                                        return False
                        return True
-               
+
                def get_missing_iuse(self, flags):
                        """
                        @returns: A list of flags missing from IUSE.
index 25d679e9f4bb0bd5fa0fb6e1e0bf0a8184b975f4..66278ec5e78577e3852876d684270f659f069e97 100644 (file)
@@ -135,3 +135,31 @@ class MaskManager(object):
                                                        return None
                                return x
                return None
+
+       def getRawMaskAtom(self, cpv, slot, repo):
+               """
+               Take a package and return a matching package.mask atom, or None if no
+               such atom exists. It HAS NOT! been cancelled by any 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: A matching atom string or None if one is not found.
+               """
+
+               cp = cpv_getkey(cpv)
+               mask_atoms = self._pmaskdict.get(cp)
+               if mask_atoms:
+                       pkg = "".join((cpv, _slot_separator, slot))
+                       if repo:
+                               pkg = "".join((pkg, _repo_separator, repo))
+                       pkg_list = [pkg]
+                       for x in mask_atoms:
+                               if not match_from_list(x, pkg_list):
+                                       continue
+                               return x
+               return None
index ba6ac21fa34a10fb8421a29eb6d43e02ad3c5882..b15a1952e8ce822e06ccfcd857cc06e6e3cc8dbf 100644 (file)
@@ -110,10 +110,10 @@ class _iuse_implicit_match_cache(object):
 class config(object):
        """
        This class encompasses the main portage configuration.  Data is pulled from
-       ROOT/PORTDIR/profiles/, from ROOT/etc/make.profile incrementally through all 
+       ROOT/PORTDIR/profiles/, from ROOT/etc/make.profile incrementally through all
        parent profiles as well as from ROOT/PORTAGE_CONFIGROOT/* for user specified
        overrides.
-       
+
        Generally if you need data like USE flags, FEATURES, environment variables,
        virtuals ...etc you look in here.
        """
@@ -1376,6 +1376,22 @@ class config(object):
                """
                return self._mask_manager.getMaskAtom(cpv, metadata["SLOT"], metadata.get('repository'))
 
+       def _getRawMaskAtom(self, cpv, metadata):
+               """
+               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 metadata: A dictionary of raw package metadata
+               @type metadata: dict
+               @rtype: String
+               @return: A matching atom string or None if one is not found.
+               """
+               return self._mask_manager.getRawMaskAtom(cpv, metadata["SLOT"], metadata.get('repository'))
+
+
        def _getProfileMaskAtom(self, cpv, metadata):
                """
                Take a package and return a matching profile atom, or None if no
@@ -1424,7 +1440,7 @@ class config(object):
                @return: A list of KEYWORDS that have not been accepted.
                """
 
-               # Hack: Need to check the env directly here as otherwise stacking 
+               # Hack: Need to check the env directly here as otherwise stacking
                # doesn't work properly as negative values are lost in the config
                # object (bug #139600)
                backuped_accept_keywords = self.configdict["backupenv"].get("ACCEPT_KEYWORDS", "")