Move most of the code to _emerge's Package object. Refine the hardmasking code, optim...
authorBrian Dolbec <brian.dolbec@gmail.com>
Sat, 29 Jan 2011 09:53:36 +0000 (01:53 -0800)
committerZac Medico <zmedico@gentoo.org>
Sun, 30 Jan 2011 09:11:58 +0000 (01:11 -0800)
pym/_emerge/Package.py
pym/_emerge/resolver/output.py

index c80bad3acb0b0680ec426247ffe0acb145d78816..e7302b3516ade51e6d0ec87305bf01980c747789 100644 (file)
@@ -41,6 +41,8 @@ class Package(Task):
 
        def __init__(self, **kwargs):
                Task.__init__(self, **kwargs)
+               # the SlotObject constructor assigns self.root_config from keyword args
+               # and is an instance of a '_emerge.RootConfig.RootConfig class
                self.root = self.root_config.root
                self._raw_metadata = _PackageMetadataWrapperBase(self.metadata)
                self.metadata = _PackageMetadataWrapper(self, self._raw_metadata)
@@ -235,6 +237,49 @@ class Package(Task):
 
                return True
 
+       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))
+               if used_keyword and len(used_keyword) == 1:
+                       used_keyword = used_keyword[0]
+               elif len(used_keyword) > 1:
+                       # you can raise an error here if you prefer, remove it, or set the correct levels
+                       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 
+               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
+                               m = self.root_config.trees['porttree'].dbapi.xmatch("match-all",x)
+                               #print "m =", m
+                               for n in m:
+                                       hardmasked.update([n])
+                               #count += 1
+                       #print "for x in n: loop count =", count, hardmasked
+                       return self.cpv in hardmasked
+               return False
+
+
        def _metadata_exception(self, k, e):
 
                # For unicode safety with python-2.x we need to avoid
index 4b90e9dd501064dd07ece64ae5ac857617bc1080..f1af30b25db3398bbe4ed586fa5fef4f0586ead2 100644 (file)
@@ -163,39 +163,20 @@ class Display(object):
                @param pkg: _emerge.Package instance
                Modifies self.verboseadd
                """
-               accept_keywords = set(self.portdb.settings['ACCEPT_KEYWORDS'].split())
-               keywords = set(self.portdb.aux_get(pkg.cpv, ["KEYWORDS"])[0].split())
-               used_keyword = list(set.intersection(keywords, accept_keywords))
-               if used_keyword and len(used_keyword) == 1:
-                       used_keyword = used_keyword[0]
-               elif len(used_keyword) > 1:
-                       # you can raise an error here if you prefer, remove it, or set the correct levels
-                       writemsg_level( "_emerge.output.resolver.Display(), too many keywords recieved for pkg: %s, %s"
-                                       % (pkg.cpv, used_keyword))
-               try:
-                       pmask = self.portdb.settings.pmaskdict[pkg.cp]
-               except KeyError:
-                       pmask = []
-               hardmasked = []
-               for x in pmask:
-                       m = self.portdb.xmatch("match-all",x)
-                       for n in m:
-                               if n not in hardmasked:
-                                       hardmasked.append(n)
-
+               used_keyword = pkg.accepted_keyword()
+               hardmasked = pkg.isHardMasked()
                text = ''
                if '~' in used_keyword:
                        text = used_keyword
                elif not used_keyword:
                        text = '**'
                if text:
-                       if pkg.cpv in hardmasked:
+                       if hardmasked:
                                self.verboseadd += red('%s ' % text)
                        else:
                                self.verboseadd += yellow('%s ' % text)
                return
 
-
        def map_to_use_expand(self, myvals, forced_flags=False,
                remove_hidden=True):
                """Map use expand variables