summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-02-25 21:38:30 +0000
committerZac Medico <zmedico@gentoo.org>2010-02-25 21:38:30 +0000
commitbb9c48210b43eb541bc2f1d3bfe2814edbc233e2 (patch)
treeda8e24882a0e6cc7c5a5e78e4c5c783652418d5e
parent55a8c061f34e15d58fb4d9889f0157c7b7e5b0c9 (diff)
downloadportage-bb9c48210b43eb541bc2f1d3bfe2814edbc233e2.tar.gz
portage-bb9c48210b43eb541bc2f1d3bfe2814edbc233e2.tar.bz2
portage-bb9c48210b43eb541bc2f1d3bfe2814edbc233e2.zip
Split getmaskingstatus and getmaskingreason info portage.package.ebuild
submodules. svn path=/main/trunk/; revision=15463
-rw-r--r--pym/portage/__init__.py213
-rw-r--r--pym/portage/package/ebuild/getmaskingreason.py78
-rw-r--r--pym/portage/package/ebuild/getmaskingstatus.py154
3 files changed, 234 insertions, 211 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 27ea106ad..d059263a9 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -110,6 +110,8 @@ try:
'portage.package.ebuild.digestcheck:digestcheck',
'portage.package.ebuild.digestgen:digestgen',
'portage.package.ebuild.fetch:fetch',
+ 'portage.package.ebuild.getmaskingreason:getmaskingreason',
+ 'portage.package.ebuild.getmaskingstatus:getmaskingstatus',
'portage.package.ebuild.prepare_build_dirs:prepare_build_dirs',
'portage.process',
'portage.process:atexit_register,run_exitfuncs',
@@ -913,217 +915,6 @@ def dep_virtual(mysplit, mysettings):
newsplit.append(x)
return newsplit
-def getmaskingreason(mycpv, metadata=None, settings=None, portdb=None, return_location=False):
- from portage.util import grablines
- if settings is None:
- settings = globals()["settings"]
- if portdb is None:
- portdb = globals()["portdb"]
- mysplit = catpkgsplit(mycpv)
- if not mysplit:
- raise ValueError(_("invalid CPV: %s") % mycpv)
- if metadata is None:
- db_keys = list(portdb._aux_cache_keys)
- try:
- metadata = dict(zip(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.
- locations = [os.path.join(settings["PORTDIR"], "profiles")]
- locations.extend(settings.profiles)
- for ov in settings["PORTDIR_OVERLAY"].split():
- profdir = os.path.join(normalize_path(ov), "profiles")
- if os.path.isdir(profdir):
- locations.append(profdir)
- locations.append(os.path.join(settings["PORTAGE_CONFIGROOT"],
- USER_CONFIG_PATH))
- locations.reverse()
- pmasklists = [(x, grablines(os.path.join(x, "package.mask"), recursive=1)) for x in locations]
-
- if mycp in settings.pmaskdict:
- for x in settings.pmaskdict[mycp]:
- if match_from_list(x, cpv_slot_list):
- for pmask in pmasklists:
- comment = ""
- comment_valid = -1
- pmask_filename = os.path.join(pmask[0], "package.mask")
- for i in range(len(pmask[1])):
- l = pmask[1][i].strip()
- if l == "":
- comment = ""
- comment_valid = -1
- elif l[0] == "#":
- comment += (l+"\n")
- comment_valid = i + 1
- elif l == x:
- if comment_valid != i:
- comment = ""
- if return_location:
- return (comment, pmask_filename)
- else:
- return comment
- elif comment_valid != -1:
- # Apparently this comment applies to muliple masks, so
- # it remains valid until a blank line is encountered.
- comment_valid += 1
- if return_location:
- return (None, None)
- else:
- return None
-
-def getmaskingstatus(mycpv, settings=None, portdb=None):
- if settings is None:
- settings = config(clone=globals()["settings"])
- if portdb is None:
- portdb = globals()["portdb"]
-
- metadata = None
- installed = False
- if not isinstance(mycpv, basestring):
- # emerge passed in a Package instance
- pkg = mycpv
- mycpv = pkg.cpv
- metadata = pkg.metadata
- installed = pkg.installed
-
- mysplit = catpkgsplit(mycpv)
- if not mysplit:
- raise ValueError(_("invalid CPV: %s") % mycpv)
- if metadata is None:
- db_keys = list(portdb._aux_cache_keys)
- try:
- metadata = dict(zip(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(mycpv, mydb=metadata)
- metadata["USE"] = settings["PORTAGE_USE"]
- else:
- metadata["USE"] = ""
- mycp=mysplit[0]+"/"+mysplit[1]
-
- rValue = []
-
- # profile checking
- if settings._getProfileMaskAtom(mycpv, metadata):
- rValue.append("profile")
-
- # package.mask checking
- if settings._getMaskAtom(mycpv, metadata):
- rValue.append("package.mask")
-
- # keywords checking
- eapi = metadata["EAPI"]
- mygroups = settings._getKeywords(mycpv, metadata)
- licenses = metadata["LICENSE"]
- properties = metadata["PROPERTIES"]
- slot = metadata["SLOT"]
- if eapi.startswith("-"):
- eapi = eapi[1:]
- if not eapi_is_supported(eapi):
- return ["EAPI %s" % eapi]
- elif _eapi_is_deprecated(eapi) and not installed:
- return ["EAPI %s" % eapi]
- egroups = settings.configdict["backupenv"].get(
- "ACCEPT_KEYWORDS", "").split()
- pgroups = settings["ACCEPT_KEYWORDS"].split()
- myarch = settings["ARCH"]
- if pgroups and myarch not in pgroups:
- """For operating systems other than Linux, ARCH is not necessarily a
- valid keyword."""
- myarch = pgroups[0].lstrip("~")
-
- cp = cpv_getkey(mycpv)
- pkgdict = settings.pkeywordsdict.get(cp)
- matches = False
- if pkgdict:
- cpv_slot_list = ["%s:%s" % (mycpv, metadata["SLOT"])]
- for atom, pkgkeywords in pkgdict.items():
- if match_from_list(atom, cpv_slot_list):
- matches = True
- pgroups.extend(pkgkeywords)
- 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
-
- kmask = "missing"
-
- if '**' in pgroups:
- kmask = None
- else:
- for keyword in pgroups:
- if keyword in mygroups:
- kmask = None
- break
-
- if kmask:
- fallback = None
- for gp in mygroups:
- if gp=="*":
- kmask=None
- break
- elif gp=="-"+myarch and myarch in pgroups:
- kmask="-"+myarch
- break
- elif gp=="~"+myarch and myarch in pgroups:
- kmask="~"+myarch
- break
-
- try:
- missing_licenses = settings._getMissingLicenses(mycpv, metadata)
- if missing_licenses:
- allowed_tokens = set(["||", "(", ")"])
- allowed_tokens.update(missing_licenses)
- license_split = licenses.split()
- license_split = [x for x in license_split \
- if x in allowed_tokens]
- msg = license_split[:]
- msg.append("license(s)")
- rValue.append(" ".join(msg))
- except portage.exception.InvalidDependString as e:
- rValue.append("LICENSE: "+str(e))
-
- try:
- missing_properties = settings._getMissingProperties(mycpv, metadata)
- if missing_properties:
- allowed_tokens = set(["||", "(", ")"])
- allowed_tokens.update(missing_properties)
- properties_split = properties.split()
- properties_split = [x for x in properties_split \
- if x in allowed_tokens]
- msg = properties_split[:]
- msg.append("properties")
- rValue.append(" ".join(msg))
- except portage.exception.InvalidDependString as e:
- rValue.append("PROPERTIES: "+str(e))
-
- # Only show KEYWORDS masks for installed packages
- # if they're not masked for any other reason.
- if kmask and (not installed or not rValue):
- rValue.append(kmask+" keyword")
-
- return rValue
-
auxdbkeys = (
'DEPEND', 'RDEPEND', 'SLOT', 'SRC_URI',
'RESTRICT', 'HOMEPAGE', 'LICENSE', 'DESCRIPTION',
diff --git a/pym/portage/package/ebuild/getmaskingreason.py b/pym/portage/package/ebuild/getmaskingreason.py
new file mode 100644
index 000000000..d0c816439
--- /dev/null
+++ b/pym/portage/package/ebuild/getmaskingreason.py
@@ -0,0 +1,78 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+__all__ = ['getmaskingreason']
+
+import portage
+from portage import os
+from portage.const import USER_CONFIG_PATH
+from portage.dep import match_from_list
+from portage.localization import _
+from portage.util import grablines, normalize_path
+from portage.versions import catpkgsplit
+
+def getmaskingreason(mycpv, metadata=None, settings=None, portdb=None, return_location=False):
+ if settings is None:
+ settings = portage.settings
+ if portdb is None:
+ portdb = portage.portdb
+ mysplit = catpkgsplit(mycpv)
+ if not mysplit:
+ raise ValueError(_("invalid CPV: %s") % mycpv)
+ if metadata is None:
+ db_keys = list(portdb._aux_cache_keys)
+ try:
+ metadata = dict(zip(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.
+ locations = [os.path.join(settings["PORTDIR"], "profiles")]
+ locations.extend(settings.profiles)
+ for ov in settings["PORTDIR_OVERLAY"].split():
+ profdir = os.path.join(normalize_path(ov), "profiles")
+ if os.path.isdir(profdir):
+ locations.append(profdir)
+ locations.append(os.path.join(settings["PORTAGE_CONFIGROOT"],
+ USER_CONFIG_PATH))
+ locations.reverse()
+ pmasklists = [(x, grablines(os.path.join(x, "package.mask"), recursive=1)) for x in locations]
+
+ if mycp in settings.pmaskdict:
+ for x in settings.pmaskdict[mycp]:
+ if match_from_list(x, cpv_slot_list):
+ for pmask in pmasklists:
+ comment = ""
+ comment_valid = -1
+ pmask_filename = os.path.join(pmask[0], "package.mask")
+ for i in range(len(pmask[1])):
+ l = pmask[1][i].strip()
+ if l == "":
+ comment = ""
+ comment_valid = -1
+ elif l[0] == "#":
+ comment += (l+"\n")
+ comment_valid = i + 1
+ elif l == x:
+ if comment_valid != i:
+ comment = ""
+ if return_location:
+ return (comment, pmask_filename)
+ else:
+ return comment
+ elif comment_valid != -1:
+ # Apparently this comment applies to muliple masks, so
+ # it remains valid until a blank line is encountered.
+ comment_valid += 1
+ if return_location:
+ return (None, None)
+ else:
+ return None
diff --git a/pym/portage/package/ebuild/getmaskingstatus.py b/pym/portage/package/ebuild/getmaskingstatus.py
new file mode 100644
index 000000000..bfe92d824
--- /dev/null
+++ b/pym/portage/package/ebuild/getmaskingstatus.py
@@ -0,0 +1,154 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+__all__ = ['getmaskingstatus']
+
+import portage
+from portage import eapi_is_supported, _eapi_is_deprecated
+from portage.dep import match_from_list
+from portage.localization import _
+from portage.package.ebuild.config import config
+from portage.versions import catpkgsplit, cpv_getkey
+
+def getmaskingstatus(mycpv, settings=None, portdb=None):
+ if settings is None:
+ settings = config(clone=portage.settings)
+ if portdb is None:
+ portdb = portage.portdb
+
+ metadata = None
+ installed = False
+ if not isinstance(mycpv, basestring):
+ # emerge passed in a Package instance
+ pkg = mycpv
+ mycpv = pkg.cpv
+ metadata = pkg.metadata
+ installed = pkg.installed
+
+ mysplit = catpkgsplit(mycpv)
+ if not mysplit:
+ raise ValueError(_("invalid CPV: %s") % mycpv)
+ if metadata is None:
+ db_keys = list(portdb._aux_cache_keys)
+ try:
+ metadata = dict(zip(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(mycpv, mydb=metadata)
+ metadata["USE"] = settings["PORTAGE_USE"]
+ else:
+ metadata["USE"] = ""
+
+ rValue = []
+
+ # profile checking
+ if settings._getProfileMaskAtom(mycpv, metadata):
+ rValue.append("profile")
+
+ # package.mask checking
+ if settings._getMaskAtom(mycpv, metadata):
+ rValue.append("package.mask")
+
+ # keywords checking
+ eapi = metadata["EAPI"]
+ mygroups = settings._getKeywords(mycpv, metadata)
+ licenses = metadata["LICENSE"]
+ properties = metadata["PROPERTIES"]
+ if eapi.startswith("-"):
+ eapi = eapi[1:]
+ if not eapi_is_supported(eapi):
+ return ["EAPI %s" % eapi]
+ elif _eapi_is_deprecated(eapi) and not installed:
+ return ["EAPI %s" % eapi]
+ egroups = settings.configdict["backupenv"].get(
+ "ACCEPT_KEYWORDS", "").split()
+ pgroups = settings["ACCEPT_KEYWORDS"].split()
+ myarch = settings["ARCH"]
+ if pgroups and myarch not in pgroups:
+ """For operating systems other than Linux, ARCH is not necessarily a
+ valid keyword."""
+ myarch = pgroups[0].lstrip("~")
+
+ cp = cpv_getkey(mycpv)
+ pkgdict = settings.pkeywordsdict.get(cp)
+ matches = False
+ if pkgdict:
+ cpv_slot_list = ["%s:%s" % (mycpv, metadata["SLOT"])]
+ for atom, pkgkeywords in pkgdict.items():
+ if match_from_list(atom, cpv_slot_list):
+ matches = True
+ pgroups.extend(pkgkeywords)
+ 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
+
+ kmask = "missing"
+
+ if '**' in pgroups:
+ kmask = None
+ else:
+ for keyword in pgroups:
+ if keyword in mygroups:
+ kmask = None
+ break
+
+ if kmask:
+ for gp in mygroups:
+ if gp=="*":
+ kmask=None
+ break
+ elif gp=="-"+myarch and myarch in pgroups:
+ kmask="-"+myarch
+ break
+ elif gp=="~"+myarch and myarch in pgroups:
+ kmask="~"+myarch
+ break
+
+ try:
+ missing_licenses = settings._getMissingLicenses(mycpv, metadata)
+ if missing_licenses:
+ allowed_tokens = set(["||", "(", ")"])
+ allowed_tokens.update(missing_licenses)
+ license_split = licenses.split()
+ license_split = [x for x in license_split \
+ if x in allowed_tokens]
+ msg = license_split[:]
+ msg.append("license(s)")
+ rValue.append(" ".join(msg))
+ except portage.exception.InvalidDependString as e:
+ rValue.append("LICENSE: "+str(e))
+
+ try:
+ missing_properties = settings._getMissingProperties(mycpv, metadata)
+ if missing_properties:
+ allowed_tokens = set(["||", "(", ")"])
+ allowed_tokens.update(missing_properties)
+ properties_split = properties.split()
+ properties_split = [x for x in properties_split \
+ if x in allowed_tokens]
+ msg = properties_split[:]
+ msg.append("properties")
+ rValue.append(" ".join(msg))
+ except portage.exception.InvalidDependString as e:
+ rValue.append("PROPERTIES: "+str(e))
+
+ # Only show KEYWORDS masks for installed packages
+ # if they're not masked for any other reason.
+ if kmask and (not installed or not rValue):
+ rValue.append(kmask+" keyword")
+
+ return rValue