From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Pm4UT-0007u8-ON for garchives@archives.gentoo.org; Sun, 06 Feb 2011 13:17:22 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id EBED5E0B97; Sun, 6 Feb 2011 13:09:54 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 927E4E0B39 for ; Sun, 6 Feb 2011 13:09:54 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 11A801B41C1 for ; Sun, 6 Feb 2011 13:09:52 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 7AE8F8006A for ; Sun, 6 Feb 2011 13:09:51 +0000 (UTC) From: "Thomas Sachau" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Thomas Sachau" Message-ID: <757d61c4041b11b124ee8baf9c2d482e15c89cb9.tommy@gentoo> Subject: [gentoo-commits] proj/portage:multilib commit in: pym/portage/package/ebuild/_config/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/package/ebuild/_config/KeywordsManager.py X-VCS-Directories: pym/portage/package/ebuild/_config/ X-VCS-Committer: tommy X-VCS-Committer-Name: Thomas Sachau X-VCS-Revision: 757d61c4041b11b124ee8baf9c2d482e15c89cb9 Date: Sun, 6 Feb 2011 13:09:51 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 5a56703e9c32206fa6e493cb7ec648f2 commit: 757d61c4041b11b124ee8baf9c2d482e15c89cb9 Author: Brian Dolbec gmail com> AuthorDate: Sun Jan 30 20:39:39 2011 +0000 Commit: Thomas Sachau gentoo org> CommitDate: Sun Jan 30 22:37:48 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D757d61c4 split up the getMissingKeywords code to eliminate code duplication and in= crease 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_list= s, writemsg from portage.versions import cpv_getkey =20 class KeywordsManager(object): + """Manager class to handle keywords processing and validation""" =20 - def __init__(self, profiles, abs_user_config, user_config=3DTrue, globa= l_accept_keywords=3D""): + def __init__(self, profiles, abs_user_config, user_config=3DTrue, + global_accept_keywords=3D""): self._pkeywords_list =3D [] rawpkeywords =3D [grabdict_package( - os.path.join(x, "package.keywords"), recursive=3D1, verify_eapi=3DTru= e) \ + os.path.join(x, "package.keywords"), recursive=3D1, + verify_eapi=3DTrue) \ for x in profiles] for pkeyworddict in rawpkeywords: if not pkeyworddict: @@ -31,7 +34,8 @@ class KeywordsManager(object): =20 self._p_accept_keywords =3D [] raw_p_accept_keywords =3D [grabdict_package( - os.path.join(x, "package.accept_keywords"), recursive=3D1, verify_eap= i=3DTrue) \ + os.path.join(x, "package.accept_keywords"), recursive=3D1, + verify_eapi=3DTrue) \ 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 =3D grabdict_package( os.path.join(abs_user_config, "package.keywords"), - recursive=3D1, allow_wildcard=3DTrue, allow_repo=3DTrue, verify_eapi= =3DFalse) + recursive=3D1, allow_wildcard=3DTrue, allow_repo=3DTrue, + verify_eapi=3DFalse) =20 for k, v in grabdict_package( os.path.join(abs_user_config, "package.accept_keywords"), - recursive=3D1, allow_wildcard=3DTrue, allow_repo=3DTrue, verify_eapi= =3DFalse).items(): + recursive=3D1, allow_wildcard=3DTrue, allow_repo=3DTrue, + verify_eapi=3DFalse).items(): pkgdict.setdefault(k, []).extend(v) =20 accept_keywords_defaults =3D global_accept_keywords.split() @@ -66,6 +72,7 @@ class KeywordsManager(object): v =3D tuple(v) self.pkeywordsdict.setdefault(k.cp, {})[k] =3D v =20 + def getKeywords(self, cpv, slot, keywords, repo): cp =3D cpv_getkey(cpv) pkg =3D "".join((cpv, _slot_separator, slot)) @@ -80,7 +87,14 @@ class KeywordsManager(object): keywords.extend(pkg_keywords) return stack_lists(keywords, incremental=3DTrue) =20 - def getMissingKeywords(self, cpv, slot, keywords, repo, global_accept_k= eywords, 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. """ =20 - # 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 =3D backuped_accept_keywords.split() mygroups =3D self.getKeywords(cpv, slot, keywords, repo) # Repoman may modify this attribute as necessary. pgroups =3D global_accept_keywords.split() - matches =3D False - cp =3D cpv_getkey(cpv) =20 - if self._p_accept_keywords: - cpv_slot =3D "%s:%s" % (cpv, slot) - accept_keywords_defaults =3D tuple('~' + keyword for keyword in \ - pgroups if keyword[:1] not in "~-") - for d in self._p_accept_keywords: - cpdict =3D d.get(cp) - if cpdict: - pkg_accept_keywords =3D \ - ordered_by_atom_specificity(cpdict, cpv_slot) - if pkg_accept_keywords: - for x in pkg_accept_keywords: - if not x: - x =3D accept_keywords_defaults - pgroups.extend(x) - matches =3D True + unmaskgroups =3D self.getPKeywords(cpv, slot, repo, + global_accept_keywords) + pgroups.extend(unmaskgroups) =20 - pkgdict =3D self.pkeywordsdict.get(cp) - if pkgdict: - cpv_slot =3D "%s:%s" % (cpv, slot) - pkg_accept_keywords =3D \ - ordered_by_atom_specificity(pkgdict, cpv_slot, repo=3Drepo) - if pkg_accept_keywords: - for x in pkg_accept_keywords: - pgroups.extend(x) - matches =3D 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 =3D self._getEgroups(backuped_accept_keywords) + pgroups.extend(egroups) =20 - if matches or egroups: - pgroups.extend(egroups) - inc_pgroups =3D set() - for x in pgroups: - if x.startswith("-"): - if x =3D=3D "-*": - inc_pgroups.clear() - else: - inc_pgroups.discard(x[1:]) - else: - inc_pgroups.add(x) - pgroups =3D inc_pgroups - del inc_pgroups + return self._getMissingKeywords(cpv, pgroups, mygroups) =20 - match =3D False - hasstable =3D False - hastesting =3D False - for gp in mygroups: - if gp =3D=3D "*" or (gp =3D=3D "-*" and len(mygroups) =3D=3D 1): - writemsg(_("--- WARNING: Package '%(cpv)s' uses" - " '%(keyword)s' keyword.\n") % {"cpv": cpv, "keyword": gp}, noisele= vel=3D-1) - if gp =3D=3D "*": - match =3D 1 - break - elif gp in pgroups: - match=3D1 - break - elif gp.startswith("~"): - hastesting =3D True - elif not gp.startswith("-"): - hasstable =3D True - if not match and \ - ((hastesting and "~*" in pgroups) or \ - (hasstable and "*" in pgroups) or "**" in pgroups): - match=3D1 - if match: - missing =3D [] - 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 =3D mygroups - return missing =20 - def getRawMissingKeywords(self, cpv, slot, keywords, repo, global_accep= t_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. """ =20 - # 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 =3D backuped_accept_keywords.split() mygroups =3D self.getKeywords(cpv, slot, keywords, repo) # Repoman may modify this attribute as necessary. pgroups =3D global_accept_keywords.split() - matches =3D False =20 - ## 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 =3D self._getEgroups(backuped_accept_keywords) + egroups =3D [x.lstrip('~') for x in egroups] + + pgroups.extend(egroups) + + missing =3D 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 =3D backuped_accept_keywords.split() + pgroups =3D [] if egroups: pgroups.extend(egroups) inc_pgroups =3D 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 =3D inc_pgroups del inc_pgroups + return pgroups + =20 + @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 =3D False hasstable =3D False hastesting =3D False for gp in mygroups: if gp =3D=3D "*" or (gp =3D=3D "-*" and len(mygroups) =3D=3D 1): writemsg(_("--- WARNING: Package '%(cpv)s' uses" - " '%(keyword)s' keyword.\n") % {"cpv": cpv, "keyword": gp}, noisele= vel=3D-1) + " '%(keyword)s' keyword.\n") % {"cpv": cpv, "keyword": gp}, + noiselevel=3D-1) if gp =3D=3D "*": - match =3D 1 + match =3D True break elif gp in pgroups: - match=3D1 + match =3D True break elif gp.startswith("~"): hastesting =3D 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=3D1 + match =3D True if match: missing =3D [] else: @@ -261,4 +248,53 @@ class KeywordsManager(object): # in order to distinguish from the case of "none missing". mygroups.append("**") missing =3D 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 =3D global_accept_keywords.split() + cp =3D cpv_getkey(cpv) + + unmaskgroups =3D [] + if self._p_accept_keywords: + cpv_slot =3D "%s:%s" % (cpv, slot) + accept_keywords_defaults =3D tuple('~' + keyword for keyword in \ + pgroups if keyword[:1] not in "~-") + for d in self._p_accept_keywords: + cpdict =3D d.get(cp) + if cpdict: + pkg_accept_keywords =3D \ + ordered_by_atom_specificity(cpdict, cpv_slot) + if pkg_accept_keywords: + for x in pkg_accept_keywords: + if not x: + x =3D accept_keywords_defaults + unmaskgroups.extend(x) + + pkgdict =3D self.pkeywordsdict.get(cp) + if pkgdict: + cpv_slot =3D "%s:%s" % (cpv, slot) + pkg_accept_keywords =3D \ + ordered_by_atom_specificity(pkgdict, cpv_slot, repo=3Drepo) + if pkg_accept_keywords: + for x in pkg_accept_keywords: + unmaskgroups.extend(x) + return unmaskgroups +