From: "Thomas Sachau" <tommy@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:multilib commit in: pym/portage/package/ebuild/_config/
Date: Sun, 6 Feb 2011 13:09:51 +0000 (UTC) [thread overview]
Message-ID: <757d61c4041b11b124ee8baf9c2d482e15c89cb9.tommy@gentoo> (raw)
commit: 757d61c4041b11b124ee8baf9c2d482e15c89cb9
Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
AuthorDate: Sun Jan 30 20:39:39 2011 +0000
Commit: Thomas Sachau <tommy <AT> gentoo <DOT> org>
CommitDate: Sun Jan 30 22:37:48 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=757d61c4
split up the getMissingKeywords code to eliminate code duplication and increase flexibility. Do some pyflakes and pylint cleanup
---
.../package/ebuild/_config/KeywordsManager.py | 224 +++++++++++--------
1 files changed, 130 insertions(+), 94 deletions(-)
diff --git a/pym/portage/package/ebuild/_config/KeywordsManager.py b/pym/portage/package/ebuild/_config/KeywordsManager.py
index bff7afa..8a6b4bd 100644
--- a/pym/portage/package/ebuild/_config/KeywordsManager.py
+++ b/pym/portage/package/ebuild/_config/KeywordsManager.py
@@ -13,11 +13,14 @@ from portage.util import grabdict_package, stack_lists, writemsg
from portage.versions import cpv_getkey
class KeywordsManager(object):
+ """Manager class to handle keywords processing and validation"""
- def __init__(self, profiles, abs_user_config, user_config=True, global_accept_keywords=""):
+ def __init__(self, profiles, abs_user_config, user_config=True,
+ global_accept_keywords=""):
self._pkeywords_list = []
rawpkeywords = [grabdict_package(
- os.path.join(x, "package.keywords"), recursive=1, verify_eapi=True) \
+ os.path.join(x, "package.keywords"), recursive=1,
+ verify_eapi=True) \
for x in profiles]
for pkeyworddict in rawpkeywords:
if not pkeyworddict:
@@ -31,7 +34,8 @@ class KeywordsManager(object):
self._p_accept_keywords = []
raw_p_accept_keywords = [grabdict_package(
- os.path.join(x, "package.accept_keywords"), recursive=1, verify_eapi=True) \
+ os.path.join(x, "package.accept_keywords"), recursive=1,
+ verify_eapi=True) \
for x in profiles]
for d in raw_p_accept_keywords:
if not d:
@@ -48,11 +52,13 @@ class KeywordsManager(object):
if user_config:
pkgdict = grabdict_package(
os.path.join(abs_user_config, "package.keywords"),
- recursive=1, allow_wildcard=True, allow_repo=True, verify_eapi=False)
+ recursive=1, allow_wildcard=True, allow_repo=True,
+ verify_eapi=False)
for k, v in grabdict_package(
os.path.join(abs_user_config, "package.accept_keywords"),
- recursive=1, allow_wildcard=True, allow_repo=True, verify_eapi=False).items():
+ recursive=1, allow_wildcard=True, allow_repo=True,
+ verify_eapi=False).items():
pkgdict.setdefault(k, []).extend(v)
accept_keywords_defaults = global_accept_keywords.split()
@@ -66,6 +72,7 @@ class KeywordsManager(object):
v = tuple(v)
self.pkeywordsdict.setdefault(k.cp, {})[k] = v
+
def getKeywords(self, cpv, slot, keywords, repo):
cp = cpv_getkey(cpv)
pkg = "".join((cpv, _slot_separator, slot))
@@ -80,7 +87,14 @@ class KeywordsManager(object):
keywords.extend(pkg_keywords)
return stack_lists(keywords, incremental=True)
- def getMissingKeywords(self, cpv, slot, keywords, repo, global_accept_keywords, backuped_accept_keywords):
+
+ def getMissingKeywords(self,
+ cpv,
+ slot,
+ keywords,
+ repo,
+ global_accept_keywords,
+ backuped_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
@@ -102,88 +116,30 @@ class KeywordsManager(object):
@return: A list of KEYWORDS that have not been accepted.
"""
- # 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)
- egroups = backuped_accept_keywords.split()
mygroups = self.getKeywords(cpv, slot, keywords, repo)
# Repoman may modify this attribute as necessary.
pgroups = global_accept_keywords.split()
- matches = False
- cp = cpv_getkey(cpv)
- if self._p_accept_keywords:
- cpv_slot = "%s:%s" % (cpv, slot)
- accept_keywords_defaults = tuple('~' + keyword for keyword in \
- pgroups if keyword[:1] not in "~-")
- for d in self._p_accept_keywords:
- cpdict = d.get(cp)
- if cpdict:
- pkg_accept_keywords = \
- ordered_by_atom_specificity(cpdict, cpv_slot)
- if pkg_accept_keywords:
- for x in pkg_accept_keywords:
- if not x:
- x = accept_keywords_defaults
- pgroups.extend(x)
- matches = True
+ unmaskgroups = self.getPKeywords(cpv, slot, repo,
+ global_accept_keywords)
+ pgroups.extend(unmaskgroups)
- pkgdict = self.pkeywordsdict.get(cp)
- if pkgdict:
- cpv_slot = "%s:%s" % (cpv, slot)
- pkg_accept_keywords = \
- ordered_by_atom_specificity(pkgdict, cpv_slot, repo=repo)
- if pkg_accept_keywords:
- for x in pkg_accept_keywords:
- pgroups.extend(x)
- matches = True
+ # 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)
+ egroups = self._getEgroups(backuped_accept_keywords)
+ pgroups.extend(egroups)
- if matches or egroups:
- pgroups.extend(egroups)
- inc_pgroups = set()
- for x in pgroups:
- if x.startswith("-"):
- if x == "-*":
- inc_pgroups.clear()
- else:
- inc_pgroups.discard(x[1:])
- else:
- inc_pgroups.add(x)
- pgroups = inc_pgroups
- del inc_pgroups
+ return self._getMissingKeywords(cpv, pgroups, mygroups)
- match = False
- hasstable = False
- hastesting = False
- for gp in mygroups:
- if gp == "*" or (gp == "-*" and len(mygroups) == 1):
- writemsg(_("--- WARNING: Package '%(cpv)s' uses"
- " '%(keyword)s' keyword.\n") % {"cpv": cpv, "keyword": gp}, noiselevel=-1)
- if gp == "*":
- match = 1
- break
- elif gp in pgroups:
- match=1
- break
- elif gp.startswith("~"):
- hastesting = True
- elif not gp.startswith("-"):
- hasstable = True
- if not match and \
- ((hastesting and "~*" in pgroups) or \
- (hasstable and "*" in pgroups) or "**" in pgroups):
- match=1
- if match:
- missing = []
- else:
- if not mygroups:
- # If KEYWORDS is empty then we still have to return something
- # in order to distinguish from the case of "none missing".
- mygroups.append("**")
- missing = mygroups
- return missing
- def getRawMissingKeywords(self, cpv, slot, keywords, repo, global_accept_keywords, backuped_accept_keywords):
+ def getRawMissingKeywords(self,
+ cpv,
+ slot,
+ keywords,
+ repo,
+ global_accept_keywords,
+ backuped_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,
@@ -206,18 +162,37 @@ class KeywordsManager(object):
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)
- egroups = backuped_accept_keywords.split()
mygroups = self.getKeywords(cpv, slot, keywords, repo)
# Repoman may modify this attribute as necessary.
pgroups = global_accept_keywords.split()
- matches = False
- ## we want to use the environment keywords here,
- ## but stripped to it's base arch
- ## we want the raw keywords needed to be accepted from the ebuild
+ # 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)
+ # we want to use the environment keywords here,
+ # but stripped to it's base arch
+ # we want the raw keywords needed to be accepted from the ebuild
+ egroups = self._getEgroups(backuped_accept_keywords)
+ egroups = [x.lstrip('~') for x in egroups]
+
+ pgroups.extend(egroups)
+
+ missing = self._getMissingKeywords(cpv, pgroups, mygroups)
+
+ return missing, pgroups
+
+
+ @staticmethod
+ def _getEgroups(backuped_accept_keywords):
+ """gets any keywords defined in the environment
+
+ @param backuped_accept_keywords: ACCEPT_KEYWORDS from the backup env
+ @type backuped_accept_keywords: String
+ @rtype: List
+ @return: list of KEYWORDS that have been accepted
+ """
+ egroups = backuped_accept_keywords.split()
+ pgroups = []
if egroups:
pgroups.extend(egroups)
inc_pgroups = set()
@@ -228,22 +203,34 @@ class KeywordsManager(object):
else:
inc_pgroups.discard(x[1:])
else:
- inc_pgroups.add(x.lstrip('~'))
+ inc_pgroups.add(x)
pgroups = inc_pgroups
del inc_pgroups
+ return pgroups
+
+ @staticmethod
+ def _getMissingKeywords(cpv, pgroups, mygroups):
+ """Determines the missing keywords
+
+ @param pgroups: The pkg keywords accepted
+ @type pgroups: list
+ @param mygroups: The ebuild keywords
+ @type mygroups: list
+ """
match = False
hasstable = False
hastesting = False
for gp in mygroups:
if gp == "*" or (gp == "-*" and len(mygroups) == 1):
writemsg(_("--- WARNING: Package '%(cpv)s' uses"
- " '%(keyword)s' keyword.\n") % {"cpv": cpv, "keyword": gp}, noiselevel=-1)
+ " '%(keyword)s' keyword.\n") % {"cpv": cpv, "keyword": gp},
+ noiselevel=-1)
if gp == "*":
- match = 1
+ match = True
break
elif gp in pgroups:
- match=1
+ match = True
break
elif gp.startswith("~"):
hastesting = True
@@ -252,7 +239,7 @@ class KeywordsManager(object):
if not match and \
((hastesting and "~*" in pgroups) or \
(hasstable and "*" in pgroups) or "**" in pgroups):
- match=1
+ match = True
if match:
missing = []
else:
@@ -261,4 +248,53 @@ class KeywordsManager(object):
# in order to distinguish from the case of "none missing".
mygroups.append("**")
missing = mygroups
- return missing, pgroups
+ return missing
+
+
+ def getPKeywords(self, cpv, slot, repo, global_accept_keywords):
+ """Gets any package.keywords settings for cp for the given
+ cpv, slot and repo
+
+ @param cpv: The package name (for package.keywords support)
+ @type cpv: String
+ @param slot: The 'SLOT' key from the raw package metadata
+ @type slot: String
+ @param keywords: The 'KEYWORDS' key from the raw package metadata
+ @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: list of KEYWORDS that have been accepted
+ """
+
+ pgroups = global_accept_keywords.split()
+ cp = cpv_getkey(cpv)
+
+ unmaskgroups = []
+ if self._p_accept_keywords:
+ cpv_slot = "%s:%s" % (cpv, slot)
+ accept_keywords_defaults = tuple('~' + keyword for keyword in \
+ pgroups if keyword[:1] not in "~-")
+ for d in self._p_accept_keywords:
+ cpdict = d.get(cp)
+ if cpdict:
+ pkg_accept_keywords = \
+ ordered_by_atom_specificity(cpdict, cpv_slot)
+ if pkg_accept_keywords:
+ for x in pkg_accept_keywords:
+ if not x:
+ x = accept_keywords_defaults
+ unmaskgroups.extend(x)
+
+ pkgdict = self.pkeywordsdict.get(cp)
+ if pkgdict:
+ cpv_slot = "%s:%s" % (cpv, slot)
+ pkg_accept_keywords = \
+ ordered_by_atom_specificity(pkgdict, cpv_slot, repo=repo)
+ if pkg_accept_keywords:
+ for x in pkg_accept_keywords:
+ unmaskgroups.extend(x)
+ return unmaskgroups
+
next reply other threads:[~2011-02-06 13:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-06 13:09 Thomas Sachau [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-02-06 13:09 [gentoo-commits] proj/portage:multilib commit in: pym/portage/package/ebuild/_config/ Thomas Sachau
2011-02-06 13:09 Thomas Sachau
2011-02-06 13:09 Thomas Sachau
2011-02-06 13:09 Thomas Sachau
2011-02-06 13:09 Thomas Sachau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=757d61c4041b11b124ee8baf9c2d482e15c89cb9.tommy@gentoo \
--to=tommy@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox