Display: Simplify mask code for bug #58416.
authorZac Medico <zmedico@gentoo.org>
Mon, 31 Jan 2011 10:01:48 +0000 (02:01 -0800)
committerZac Medico <zmedico@gentoo.org>
Mon, 31 Jan 2011 10:01:48 +0000 (02:01 -0800)
Hopefully this makes the logic more understandable, though it may
support fewer cases. If we want to handle more cases then hopefully
we can do it without making the code too complex.

pym/_emerge/Package.py
pym/_emerge/resolver/output.py
pym/portage/package/ebuild/_config/KeywordsManager.py
pym/portage/package/ebuild/config.py

index 9f210570d8743b0a22b57754a64046a7e5d9cf61..dcc6a0c465e6aa6606867120571ee7cb755fb776 100644 (file)
@@ -237,25 +237,26 @@ class Package(Task):
 
                return True
 
-       def accepted_keyword(self):
-               """returns the keyword used from the ebuild's KEYWORDS string"""
+       def get_keyword_mask(self):
+               """returns None, 'missing', or 'unstable'."""
 
-               missing, _keywords = \
-                       self.root_config.settings._getRawMissingKeywords(
-                               self.cpv, self.metadata)
-               unmasks = self.root_config.settings._getPKeywords(
+               missing = self.root_config.settings._getRawMissingKeywords(
                                self.cpv, self.metadata)
 
+               if not missing:
+                       return None
+
                if '**' in missing:
-                       return '**'
-               if missing: # keywords to evaluate
-                       for keyword in _keywords + unmasks:
-                               if keyword == '**':
-                                       return keyword
-                               used_keyword = '~' + keyword
-                               if used_keyword in missing:
-                                       return used_keyword
-               return ''
+                       return 'missing'
+
+               global_accept_keywords = frozenset(
+                       self.root_config.settings.get("ACCEPT_KEYWORDS", "").split())
+
+               for keyword in missing:
+                       if keyword.lstrip("~") in global_accept_keywords:
+                               return 'unstable'
+
+               return 'missing'
 
        def isHardMasked(self):
                """returns a bool if the cpv is in the list of
index be07656a47799ebb8b903d82683d38b06a67cc85..46e22808a8fe55472d800125809cc5b9e07638f5 100644 (file)
@@ -164,16 +164,17 @@ class Display(object):
                """
                @param pkg: _emerge.Package instance
                """
-               used_keyword = pkg.accepted_keyword()
                hardmasked = pkg.isHardMasked()
                mask_str = " "
 
                if hardmasked:
                        mask_str = colorize("BAD", "#")
-               elif not used_keyword:
-                       pass
-               elif used_keyword not in self.pkgsettings['ACCEPT_KEYWORDS'].split():
-                       if used_keyword == "**":
+               else:
+                       keyword_mask = pkg.get_keyword_mask()
+
+                       if keyword_mask is None:
+                               pass
+                       elif keyword_mask == "missing":
                                mask_str = colorize("BAD", "*")
                        else:
                                mask_str = colorize("WARN", "~")
index 0b593f6e53b7040a6bc4825299b4714c188fdfc9..51270f2d3ab65efe3e7b8ca103a3117e1c409bb5 100644 (file)
@@ -142,14 +142,13 @@ class KeywordsManager(object):
                                                        slot,
                                                        keywords,
                                                        repo,
-                                                       global_accept_keywords,
-                                                       backuped_accept_keywords):
+                                                       global_accept_keywords):
                """
                Take a package and return a list of any KEYWORDS that the user may
                need to accept for the given package. If the KEYWORDS are empty,
                the returned list will contain ** alone (in order to distinguish
                from the case of "none missing").  This DOES NOT apply any user config
-               keywording acceptance.
+               package.accept_keywords acceptance.
 
                @param cpv: The package name (for package.keywords support)
                @type cpv: String
@@ -159,29 +158,15 @@ class KeywordsManager(object):
                @type keywords: String
                @param global_accept_keywords: The current value of ACCEPT_KEYWORDS
                @type global_accept_keywords: String
-               @param backuped_accept_keywords: ACCEPT_KEYWORDS from the backup env
-               @type backuped_accept_keywords: String
                @rtype: List
                @return: lists of KEYWORDS that have not been accepted
                and the keywords it looked for.
                """
 
                mygroups = self.getKeywords(cpv, slot, keywords, repo)
-               # Repoman may modify this attribute as necessary.
                pgroups = global_accept_keywords.split()
-
-               # 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)
-               if backuped_accept_keywords:
-                       pgroups = self._getEgroups(backuped_accept_keywords.split(),
-                                       pgroups)
-               else:
-                       pgroups = set(pgroups)
-
-               missing = self._getMissingKeywords(cpv, pgroups, mygroups)
-
-               return missing, list(pgroups)
+               pgroups = set(pgroups)
+               return self._getMissingKeywords(cpv, pgroups, mygroups)
 
 
        @staticmethod
index 81657aa3866468477dc150713be2d90f5910b8f3..1f943e473272f6bd31a140a7d102f42cc0494405 100644 (file)
@@ -1456,7 +1456,7 @@ class config(object):
                need to accept for the given package. If the KEYWORDS are empty,
                the returned list will contain ** alone (in order to distinguish
                from the case of "none missing").  This DOES NOT apply any user config
-               keywording acceptance.
+               package.accept_keywords acceptance.
 
                @param cpv: The package name (for package.keywords support)
                @type cpv: String
@@ -1466,15 +1466,9 @@ class config(object):
                @return: lists of KEYWORDS that have not been accepted
                and the keywords it looked for.
                """
-
-               # 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", "")
-
                return self._keywords_manager.getRawMissingKeywords(cpv, metadata["SLOT"], \
                        metadata.get("KEYWORDS", ""), metadata.get('repository'), \
-                       self.get("ACCEPT_KEYWORDS", ""), backuped_accept_keywords)
+                       self.get("ACCEPT_KEYWORDS", ""))
 
        def _getPKeywords(self, cpv, metadata):
                global_accept_keywords = self.get("ACCEPT_KEYWORDS", "")