From 6fbb1c1c70ba82a2a06531e69b9851bf01c42e12 Mon Sep 17 00:00:00 2001 From: Brian Dolbec Date: Sat, 29 Jan 2011 01:53:36 -0800 Subject: [PATCH] Move most of the code to _emerge's Package object. Refine the hardmasking code, optimizing as much as possible. --- pym/_emerge/Package.py | 45 ++++++++++++++++++++++++++++++++++ pym/_emerge/resolver/output.py | 25 +++---------------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py index c80bad3ac..e7302b351 100644 --- a/pym/_emerge/Package.py +++ b/pym/_emerge/Package.py @@ -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 diff --git a/pym/_emerge/resolver/output.py b/pym/_emerge/resolver/output.py index 4b90e9dd5..f1af30b25 100644 --- a/pym/_emerge/resolver/output.py +++ b/pym/_emerge/resolver/output.py @@ -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 -- 2.26.2