Factor package.mask and profile masking logic out of
authorZac Medico <zmedico@gentoo.org>
Sun, 7 Oct 2007 23:04:52 +0000 (23:04 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 7 Oct 2007 23:04:52 +0000 (23:04 -0000)
portdbapi.visible() and move it to config.getMaskAtom()
and getProfileMaskAtom(). This will allow the code to
be reused for binary packages.

svn path=/main/trunk/; revision=8001

pym/portage/__init__.py
pym/portage/dbapi/porttree.py

index e2f4987608d6f7d22470f521141dc02d20b9fe5a..a8a7ea561eb3b9364246972c4cdb6d2f8173549d 100644 (file)
@@ -1838,6 +1838,64 @@ class config(object):
                if has_changed:
                        self.reset(keeping_pkg=1,use_cache=use_cache)
 
+       def getMaskAtom(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: 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
+                               masked = True
+                               if unmask_atoms:
+                                       for y in unmask_atoms:
+                                               if match_from_list(y, pkg_list):
+                                                       masked = False
+                                                       break
+                               if not masked:
+                                       continue
+                               return x
+               return None
+
+       def getProfileMaskAtom(self, cpv, metadata):
+               """
+               Take a package and return a matching profile atom, or None if no
+               such atom exists. Note that a profile atom may or may not have a "*"
+               prefix. 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: An matching profile atom string or None if one is not found.
+               """
+
+               cp = cpv_getkey(cpv)
+               profile_atoms = self.prevmaskdict.get(cp)
+               if profile_atoms:
+                       pkg_list = ["%s:%s" % (cpv, metadata["SLOT"])]
+                       for x in profile_atoms:
+                               if match_from_list(x.lstrip("*"), pkg_list):
+                                       continue
+                               return x
+               return None
+
        def getMissingKeywords(self, cpv, metadata):
                """
                Take a package and return a list of any KEYWORDS that the user may
index 14a50b126eaa3ca1f1f7b369d43a8f4cf0f0d51b..ee8c4776d622bbe6a9059dde2e16731d5e80b37d 100644 (file)
@@ -604,57 +604,22 @@ class portdbapi(dbapi):
                if not mylist:
                        return []
 
-               mysplit = catpkgsplit(mylist[0])
-               if not mysplit:
-                       #invalid cat/pkg-v
-                       writemsg("visible(): invalid cat/pkg-v: %s\n" % (mylist[0], ),
-                               noiselevel=-1)
-                       return []
-               mycp = "%s/%s" % (mysplit[0], mysplit[1])
-
-               cpv_slots = []
+               db_keys = ["SLOT"]
+               visible = []
+               getMaskAtom = self.mysettings.getMaskAtom
+               getProfileMaskAtom = self.mysettings.getProfileMaskAtom
                for cpv in mylist:
                        try:
-                               myslot = self.aux_get(cpv, ["SLOT"])[0]
+                               metadata = dict(izip(db_keys, self.aux_get(cpv, db_keys)))
                        except KeyError:
                                # masked by corruption
                                continue
-                       cpv_slots.append("%s:%s" % (cpv, myslot))
-
-               if cpv_slots:
-                       mask_atoms = self.mysettings.pmaskdict.get(mycp)
-                       if mask_atoms:
-                               unmask_atoms = self.mysettings.punmaskdict.get(mycp)
-                               for x in mask_atoms:
-                                       masked_pkgs = match_from_list(x, cpv_slots)
-                                       if not masked_pkgs:
-                                               continue
-                                       if unmask_atoms:
-                                               for y in unmask_atoms:
-                                                       unmasked_pkgs = match_from_list(y, masked_pkgs)
-                                                       if unmasked_pkgs:
-                                                               masked_pkgs = [pkg for pkg in masked_pkgs \
-                                                                       if pkg not in unmasked_pkgs]
-                                                               if not masked_pkgs:
-                                                                       break
-                                       if masked_pkgs:
-                                               cpv_slots = [pkg for pkg in cpv_slots \
-                                                       if pkg not in masked_pkgs]
-                                               if not cpv_slots:
-                                                       break
-
-               if cpv_slots:
-                       profile_atoms = self.mysettings.prevmaskdict.get(mycp)
-                       if profile_atoms:
-                               for x in profile_atoms:
-                                       cpv_slots = match_from_list(x.lstrip("*"), cpv_slots)
-                                       if not cpv_slots:
-                                               break
-
-               if not cpv_slots:
-                       return cpv_slots
-
-               return [remove_slot(pkg) for pkg in cpv_slots]
+                       if getMaskAtom(cpv, metadata):
+                               continue
+                       if getProfileMaskAtom(cpv, metadata):
+                               continue
+                       visible.append(cpv)
+               return visible
 
        def gvisible(self,mylist):
                "strip out group-masked (not in current group) entries"