From: Zac Medico Date: Tue, 9 Oct 2007 23:36:16 +0000 (-0000) Subject: Unify the masking reasons output so that the same code X-Git-Tag: v2.2_pre1~664 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b2b47aea87f1d17bcea196a7e00eb2828a3d3472;p=portage.git Unify the masking reasons output so that the same code path is used for both ebuilds and binary packages. svn path=/main/trunk/; revision=8033 --- diff --git a/pym/emerge/__init__.py b/pym/emerge/__init__.py index d02fe4770..09cac4a72 100644 --- a/pym/emerge/__init__.py +++ b/pym/emerge/__init__.py @@ -2156,80 +2156,84 @@ class depgraph(object): xfrom = '(dependency required by '+ \ green('"%s"' % myparent[2]) + \ red(' [%s]' % myparent[0]) + ')' - alleb = portdb.xmatch("match-all", x) - if alleb: - if "--usepkgonly" not in self.myopts: - print "\n!!! "+red("All ebuilds that could satisfy ")+green(xinfo)+red(" have been masked.") - print "!!! One of the following masked packages is required to complete your request:" - oldcomment = "" - shown_licenses = [] - portdb_keys = ["LICENSE","SLOT"] - for p in alleb: - mreasons = portage.getmaskingstatus(p, - settings=pkgsettings, portdb=portdb) - print "- "+p+" (masked by: "+", ".join(mreasons)+")" - if "package.mask" in mreasons: - comment, filename = \ - portage.getmaskingreason(p, - settings=pkgsettings, portdb=portdb, - return_location=True) - if comment and comment != oldcomment: - print filename+":" - print comment - oldcomment = comment - try: - metadata = dict(izip(portdb_keys, - portdb.aux_get(p, portdb_keys))) - except KeyError: - # Corruption will have been reported above. - continue - metadata["USE"] = "" + masked_packages = [] + missing_licenses = [] + dbs = self._filtered_trees[myroot]["dbs"] + for db, pkg_type, built, installed, db_keys in dbs: + match = db.match + if hasattr(db, "xmatch"): + def match(atom): + return db.xmatch("match-all", atom) + cpv_list = match(x) + cpv_sort_descending(cpv_list) + for cpv in cpv_list: + try: + metadata = dict(izip(db_keys, + db.aux_get(cpv, db_keys))) + except KeyError: + mreasons = ["corruption"] + metadata = None + if metadata and not built: if "?" in metadata["LICENSE"]: pkgsettings.setcpv(p, mydb=portdb) metadata["USE"] = pkgsettings.get("USE", "") - missing_licenses = [] + else: + metadata["USE"] = "" + mreasons = portage.getmaskingstatus( + cpv, metadata=metadata, + settings=pkgsettings, portdb=portdb) + comment, filename = None, None + if "package.mask" in mreasons: + comment, filename = \ + portage.getmaskingreason( + cpv, metadata=metadata, + settings=pkgsettings, portdb=portdb, + return_location=True) + if built and \ + metadata["CHOST"] != pkgsettings["CHOST"]: + mreasons.append("CHOST: %s" % \ + metadata["CHOST"]) + missing_licenses = [] + if metadata: try: missing_licenses = \ pkgsettings.getMissingLicenses( - p, metadata) + cpv, metadata) except portage.exception.InvalidDependString: # This will have already been reported # above via mreasons. pass - for l in missing_licenses: - l_path = portdb.findLicensePath(l) - if l in shown_licenses: - continue - msg = ("A copy of the '%s' license" + \ - " is located at '%s'.") % (l, l_path) - print msg - print - shown_licenses.append(l) - print - print "For more information, see MASKED PACKAGES section in the emerge man page or " - print "refer to the Gentoo Handbook." - else: - print - alleb = bindb.match(x) - if alleb: - chost = pkgsettings["CHOST"] - bindb_keys = ["CHOST","EAPI"] - for p in alleb: - mreasons = [] - metadata = dict(izip(bindb_keys, - bindb.aux_get(pkg, bindb_keys))) - if chost != metadata["CHOST"]: - mreasons.append("CHOST: %s" % \ - metadata["CHOST"]) - if not portage.eapi_is_supported( - metadata["EAPI"]): - mreasons.append(("required EAPI %s" + \ - ", supported EAPI %s") % \ - (metadata["EAPI"], - portage.const.EAPI)) - print "- "+p+" (masked by: "+", ".join(mreasons)+")" - print "!!! "+red("There are no packages available to satisfy: ")+green(xinfo) - print "!!! Either add a suitable binary package or compile from an ebuild." + masked_packages.append((cpv, mreasons, + comment, filename, missing_licenses)) + if masked_packages: + print "\n!!! "+red("All ebuilds that could satisfy ")+green(xinfo)+red(" have been masked.") + print "!!! One of the following masked packages is required to complete your request:" + shown_licenses = set() + shown_comments = set() + # Maybe there is both an ebuild and a binary. Only + # show one of them to avoid redundant appearance. + shown_cpvs = set() + for cpv, mreasons, comment, filename, missing_licenses in masked_packages: + if cpv in shown_cpvs: + continue + shown_cpvs.add(cpv) + print "- "+cpv+" (masked by: "+", ".join(mreasons)+")" + if comment and comment not in shown_comments: + print filename+":" + print comment + shown_comments.add(comment) + for l in missing_licenses: + l_path = portdb.findLicensePath(l) + if l in shown_licenses: + continue + msg = ("A copy of the '%s' license" + \ + " is located at '%s'.") % (l, l_path) + print msg + print + shown_licenses.add(l) + print + print "For more information, see MASKED PACKAGES section in the emerge man page or " + print "refer to the Gentoo Handbook." else: print "\nemerge: there are no ebuilds to satisfy "+green(xinfo)+"." if myparent: diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index a8a7ea561..b99805d0b 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -5062,7 +5062,7 @@ def cpv_expand(mycpv, mydb=None, use_cache=1, settings=None): else: return mykey -def getmaskingreason(mycpv, settings=None, portdb=None, return_location=False): +def getmaskingreason(mycpv, metadata=None, settings=None, portdb=None, return_location=False): from portage.util import grablines if settings is None: settings = globals()["settings"] @@ -5071,8 +5071,18 @@ def getmaskingreason(mycpv, settings=None, portdb=None, return_location=False): mysplit = catpkgsplit(mycpv) if not mysplit: raise ValueError("invalid CPV: %s" % mycpv) - if not portdb.cpv_exists(mycpv): - raise KeyError("CPV %s does not exist" % mycpv) + if metadata is None: + db_keys = list(portdb._aux_cache_keys) + try: + metadata = dict(izip(db_keys, portdb.aux_get(mycpv, db_keys))) + except KeyError: + if not portdb.cpv_exists(mycpv): + raise + if metadata is None: + # Can't access SLOT due to corruption. + cpv_slot_list = [mycpv] + else: + cpv_slot_list = ["%s:%s" % (mycpv, metadata["SLOT"])] mycp=mysplit[0]+"/"+mysplit[1] # XXX- This is a temporary duplicate of code from the config constructor. @@ -5089,7 +5099,7 @@ def getmaskingreason(mycpv, settings=None, portdb=None, return_location=False): if settings.pmaskdict.has_key(mycp): for x in settings.pmaskdict[mycp]: - if mycpv in portdb.xmatch("match-all", x): + if match_from_list(x, cpv_slot_list): comment = "" l = "\n" comment_valid = -1 @@ -5119,7 +5129,7 @@ def getmaskingreason(mycpv, settings=None, portdb=None, return_location=False): else: return None -def getmaskingstatus(mycpv, settings=None, portdb=None): +def getmaskingstatus(mycpv, metadata=None, settings=None, portdb=None): if settings is None: settings = config(clone=globals()["settings"]) if portdb is None: @@ -5127,47 +5137,37 @@ def getmaskingstatus(mycpv, settings=None, portdb=None): mysplit = catpkgsplit(mycpv) if not mysplit: raise ValueError("invalid CPV: %s" % mycpv) - if not portdb.cpv_exists(mycpv): - raise KeyError("CPV %s does not exist" % mycpv) + if metadata is None: + db_keys = list(portdb._aux_cache_keys) + try: + metadata = dict(izip(db_keys, portdb.aux_get(mycpv, db_keys))) + except KeyError: + if not portdb.cpv_exists(mycpv): + raise + return ["corruption"] + if "?" in metadata["LICENSE"]: + settings.setcpv(p, mydb=metadata) + metadata["USE"] = settings.get("USE", "") + else: + metadata["USE"] = "" + cpv_slot_list = ["%s:%s" % (mycpv, metadata["SLOT"])] mycp=mysplit[0]+"/"+mysplit[1] rValue = [] # profile checking - revmaskdict=settings.prevmaskdict - if revmaskdict.has_key(mycp): - for x in revmaskdict[mycp]: - if x[0]=="*": - myatom = x[1:] - else: - myatom = x - if not match_to_list(mycpv, [myatom]): - rValue.append("profile") - break + if settings.getProfileMaskAtom(mycpv, metadata): + rValue.append("profile") # package.mask checking - maskdict=settings.pmaskdict - unmaskdict=settings.punmaskdict - if maskdict.has_key(mycp): - for x in maskdict[mycp]: - if mycpv in portdb.xmatch("match-all", x): - unmask=0 - if unmaskdict.has_key(mycp): - for z in unmaskdict[mycp]: - if mycpv in portdb.xmatch("match-all",z): - unmask=1 - break - if unmask==0: - rValue.append("package.mask") + if settings.getMaskAtom(mycpv, metadata): + rValue.append("package.mask") # keywords checking - try: - eapi, mygroups, licenses, slot = portdb.aux_get( - mycpv, ["EAPI", "KEYWORDS", "LICENSE", "SLOT"]) - except KeyError: - # The "depend" phase apparently failed for some reason. An associated - # error message will have already been printed to stderr. - return ["corruption"] + eapi = metadata["EAPI"] + mygroups = metadata["KEYWORDS"] + licenses = metadata["LICENSE"] + slot = metadata["SLOT"] if eapi.startswith("-"): eapi = eapi[1:] if not eapi_is_supported(eapi): @@ -5183,7 +5183,10 @@ def getmaskingstatus(mycpv, settings=None, portdb=None): cp = dep_getkey(mycpv) if pkgdict.has_key(cp): - matches = match_to_list(mycpv, pkgdict[cp].keys()) + matches = [] + for match in pkgdict[cp]: + if match_from_list(match, cpv_slot_list): + matches.append(match) for match in matches: pgroups.extend(pkgdict[cp][match]) if matches: @@ -5223,13 +5226,8 @@ def getmaskingstatus(mycpv, settings=None, portdb=None): if kmask: rValue.append(kmask+" keyword") - use = "" - if "?" in licenses: - settings.setcpv(mycpv, mydb=portdb) - use = settings.get("USE", "") try: - missing_licenses = settings.getMissingLicenses( - mycpv, {"LICENSE":licenses, "SLOT":slot, "USE":use}) + missing_licenses = settings.getMissingLicenses(mycpv, metadata) if missing_licenses: allowed_tokens = set(["||", "(", ")"]) allowed_tokens.update(missing_licenses)