From af50fee789e71c1fff0b405db4cf55b618b73466 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 12 May 2012 18:07:29 -0700 Subject: [PATCH] _pkg_str: add slot and repo attributes --- pym/_emerge/Package.py | 12 ++++++----- pym/portage/dbapi/__init__.py | 14 +++++++++---- .../package/ebuild/_config/KeywordsManager.py | 21 ++++++++++--------- .../package/ebuild/_config/LicenseManager.py | 9 ++++---- .../package/ebuild/_config/UseManager.py | 12 +++++++---- pym/portage/package/ebuild/_config/helper.py | 4 ++-- pym/portage/package/ebuild/config.py | 10 +++++---- .../package/ebuild/getmaskingstatus.py | 14 ++++++++----- pym/portage/versions.py | 8 +++++-- 9 files changed, 64 insertions(+), 40 deletions(-) diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py index ec0c3f6d4..69739acc4 100644 --- a/pym/_emerge/Package.py +++ b/pym/_emerge/Package.py @@ -10,6 +10,7 @@ from portage.const import EBUILD_PHASES from portage.dep import Atom, check_required_use, use_reduce, \ paren_enclose, _slot_re, _slot_separator, _repo_separator, \ _unknown_repo +from portage.versions import _pkg_str from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use from portage.exception import InvalidDependString from portage.repository.config import _gen_valid_repo @@ -50,7 +51,6 @@ class Package(Task): self.metadata = _PackageMetadataWrapper(self, self._raw_metadata) if not self.built: self.metadata['CHOST'] = self.root_config.settings.get('CHOST', '') - self.cp = portage.cpv_getkey(self.cpv) slot = self.slot if _slot_re.match(slot) is None: self._invalid_metadata('SLOT.invalid', @@ -58,6 +58,12 @@ class Package(Task): # Avoid an InvalidAtom exception when creating slot_atom. # This package instance will be masked due to empty SLOT. slot = '0' + repo = _gen_valid_repo(self.metadata.get('repository', '')) + if not repo: + repo = self.UNKNOWN_REPO + self.metadata['repository'] = repo + self.cpv = _pkg_str(self.cpv, slot=slot, repo=repo) + self.cp = self.cpv.cp if (self.iuse.enabled or self.iuse.disabled) and \ not eapi_has_iuse_defaults(self.metadata["EAPI"]): if not self.installed: @@ -69,10 +75,6 @@ class Package(Task): self.pv_split = self.cpv_split[1:] if self.inherited is None: self.inherited = frozenset() - repo = _gen_valid_repo(self.metadata.get('repository', '')) - if not repo: - repo = self.UNKNOWN_REPO - self.metadata['repository'] = repo self._validate_deps() self.masks = self._masks() diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py index 96e85cecd..a835d4de8 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -1,4 +1,4 @@ -# Copyright 1998-2011 Gentoo Foundation +# Copyright 1998-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 __all__ = ["dbapi"] @@ -11,7 +11,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.dep:match_from_list', 'portage.output:colorize', 'portage.util:cmp_sort_key,writemsg', - 'portage.versions:catsplit,catpkgsplit,vercmp', + 'portage.versions:catsplit,catpkgsplit,vercmp,_pkg_str', ) from portage import os @@ -155,11 +155,13 @@ class dbapi(object): 2) Check enabled/disabled flag states. """ - aux_keys = ["IUSE", "SLOT", "USE"] + aux_keys = ["IUSE", "SLOT", "USE", "repository"] for cpv in cpv_iter: try: metadata = dict(zip(aux_keys, self.aux_get(cpv, aux_keys, myrepo=atom.repo))) + if not metadata["repository"]: + del metadata["repository"] except KeyError: continue @@ -209,7 +211,11 @@ class dbapi(object): elif not self.settings.local_config: # Check masked and forced flags for repoman. - pkg = "%s:%s" % (cpv, metadata["SLOT"]) + if hasattr(cpv, 'slot'): + pkg = cpv + else: + pkg = _pkg_str(cpv, slot=metadata["SLOT"], + repo=metadata.get("repository")) usemask = self.settings._getUseMask(pkg) if usemask.intersection(atom.use.enabled): return False diff --git a/pym/portage/package/ebuild/_config/KeywordsManager.py b/pym/portage/package/ebuild/_config/KeywordsManager.py index 2f9f7b305..0c613ce04 100644 --- a/pym/portage/package/ebuild/_config/KeywordsManager.py +++ b/pym/portage/package/ebuild/_config/KeywordsManager.py @@ -1,4 +1,4 @@ -# Copyright 2010-2011 Gentoo Foundation +# Copyright 2010-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 __all__ = ( @@ -11,7 +11,7 @@ from portage.dep import ExtendedAtomDict, _repo_separator, _slot_separator from portage.localization import _ from portage.package.ebuild._config.helper import ordered_by_atom_specificity from portage.util import grabdict_package, stack_lists, writemsg -from portage.versions import cpv_getkey +from portage.versions import cpv_getkey, _pkg_str class KeywordsManager(object): """Manager class to handle keywords processing and validation""" @@ -77,10 +77,11 @@ class KeywordsManager(object): def getKeywords(self, cpv, slot, keywords, repo): - cp = cpv_getkey(cpv) - pkg = "".join((cpv, _slot_separator, slot)) - if repo and repo != Package.UNKNOWN_REPO: - pkg = "".join((pkg, _repo_separator, repo)) + if not hasattr(cpv, 'slot'): + pkg = _pkg_str(cpv, slot=slot, repo=repo) + else: + pkg = cpv + cp = pkg.cp keywords = [[x for x in keywords.split() if x != "-*"]] for pkeywords_dict in self._pkeywords_list: cpdict = pkeywords_dict.get(cp) @@ -260,18 +261,19 @@ class KeywordsManager(object): """ pgroups = global_accept_keywords.split() + if not hasattr(cpv, 'slot'): + cpv = _pkg_str(cpv, slot=slot, repo=repo) 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) + ordered_by_atom_specificity(cpdict, cpv) if pkg_accept_keywords: for x in pkg_accept_keywords: if not x: @@ -280,9 +282,8 @@ class KeywordsManager(object): 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) + ordered_by_atom_specificity(pkgdict, cpv) if pkg_accept_keywords: for x in pkg_accept_keywords: unmaskgroups.extend(x) diff --git a/pym/portage/package/ebuild/_config/LicenseManager.py b/pym/portage/package/ebuild/_config/LicenseManager.py index effd55be3..f76e7e2fe 100644 --- a/pym/portage/package/ebuild/_config/LicenseManager.py +++ b/pym/portage/package/ebuild/_config/LicenseManager.py @@ -1,4 +1,4 @@ -# Copyright 2010 Gentoo Foundation +# Copyright 201-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 __all__ = ( @@ -10,7 +10,7 @@ from portage.dep import ExtendedAtomDict, use_reduce from portage.exception import InvalidDependString from portage.localization import _ from portage.util import grabdict, grabdict_package, writemsg -from portage.versions import cpv_getkey +from portage.versions import cpv_getkey, _pkg_str from portage.package.ebuild._config.helper import ordered_by_atom_specificity @@ -119,8 +119,9 @@ class LicenseManager(object): cp = cpv_getkey(cpv) cpdict = self._plicensedict.get(cp) if cpdict: - cpv_slot = "%s:%s" % (cpv, slot) - plicence_list = ordered_by_atom_specificity(cpdict, cpv_slot, repo) + if not hasattr(cpv, slot): + cpv = _pkg_str(cpv, slot=slot, repo=repo) + plicence_list = ordered_by_atom_specificity(cpdict, cpv) if plicence_list: accept_license = list(self._accept_license) for x in plicence_list: diff --git a/pym/portage/package/ebuild/_config/UseManager.py b/pym/portage/package/ebuild/_config/UseManager.py index 0506af019..e1ec7f4a0 100644 --- a/pym/portage/package/ebuild/_config/UseManager.py +++ b/pym/portage/package/ebuild/_config/UseManager.py @@ -1,4 +1,4 @@ -# Copyright 2010-2011 Gentoo Foundation +# Copyright 2010-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 __all__ = ( @@ -7,10 +7,10 @@ __all__ = ( from _emerge.Package import Package from portage import os -from portage.dep import ExtendedAtomDict, remove_slot, _get_useflag_re +from portage.dep import dep_getrepo, dep_getslot, ExtendedAtomDict, remove_slot, _get_useflag_re from portage.localization import _ from portage.util import grabfile, grabdict_package, read_corresponding_eapi_file, stack_lists, writemsg -from portage.versions import cpv_getkey +from portage.versions import cpv_getkey, _pkg_str from portage.package.ebuild._config.helper import ordered_by_atom_specificity @@ -148,9 +148,13 @@ class UseManager(object): return frozenset(stack_lists( self._usemask_list, incremental=True)) + slot = None cp = getattr(pkg, "cp", None) if cp is None: - cp = cpv_getkey(remove_slot(pkg)) + slot = dep_getslot(pkg) + repo = dep_getrepo(pkg) + pkg = _pkg_str(remove_slot(pkg), slot=slot, repo=repo) + cp = pkg.cp usemask = [] if hasattr(pkg, "repo") and pkg.repo != Package.UNKNOWN_REPO: repos = [] diff --git a/pym/portage/package/ebuild/_config/helper.py b/pym/portage/package/ebuild/_config/helper.py index 4f4678187..ee0c090a0 100644 --- a/pym/portage/package/ebuild/_config/helper.py +++ b/pym/portage/package/ebuild/_config/helper.py @@ -1,4 +1,4 @@ -# Copyright 2010-2011 Gentoo Foundation +# Copyright 2010-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 __all__ = ( @@ -24,7 +24,7 @@ def ordered_by_atom_specificity(cpdict, pkg, repo=None): order to achieve desired results (and thus corrupting the ChangeLog like ordering of the file). """ - if repo and repo != Package.UNKNOWN_REPO: + if not hasattr(pkg, 'repo') and repo and repo != Package.UNKNOWN_REPO: pkg = pkg + _repo_separator + repo results = [] diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index 24342080f..aa4a62ea2 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -43,7 +43,7 @@ from portage.util import ensure_dirs, getconfig, grabdict, \ grabdict_package, grabfile, grabfile_package, LazyItemsDict, \ normalize_path, shlex_split, stack_dictlist, stack_dicts, stack_lists, \ writemsg, writemsg_level -from portage.versions import catpkgsplit, catsplit, cpv_getkey +from portage.versions import catpkgsplit, catsplit, cpv_getkey, _pkg_str from portage.package.ebuild._config import special_env_vars from portage.package.ebuild._config.env_var_validation import validate_cmd_var @@ -1239,7 +1239,7 @@ class config(object): slot = pkg_configdict["SLOT"] iuse = pkg_configdict["IUSE"] if pkg is None: - cpv_slot = "%s:%s" % (self.mycpv, slot) + cpv_slot = _pkg_str(self.mycpv, slot=slot, repo=repository) else: cpv_slot = pkg pkginternaluse = [] @@ -1691,11 +1691,13 @@ class config(object): @return: A list of properties that have not been accepted. """ accept_properties = self._accept_properties + if not hasattr(cpv, 'slot'): + cpv = _pkg_str(cpv, slot=metadata["SLOT"], + repo=metadata.get("repository")) cp = cpv_getkey(cpv) cpdict = self._ppropertiesdict.get(cp) if cpdict: - cpv_slot = "%s:%s" % (cpv, metadata["SLOT"]) - pproperties_list = ordered_by_atom_specificity(cpdict, cpv_slot, repo=metadata.get('repository')) + pproperties_list = ordered_by_atom_specificity(cpdict, cpv) if pproperties_list: accept_properties = list(self._accept_properties) for x in pproperties_list: diff --git a/pym/portage/package/ebuild/getmaskingstatus.py b/pym/portage/package/ebuild/getmaskingstatus.py index b89fbf53b..9bf605db6 100644 --- a/pym/portage/package/ebuild/getmaskingstatus.py +++ b/pym/portage/package/ebuild/getmaskingstatus.py @@ -1,4 +1,4 @@ -# Copyright 2010-2011 Gentoo Foundation +# Copyright 2010-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 __all__ = ['getmaskingstatus'] @@ -9,7 +9,7 @@ import portage from portage import eapi_is_supported, _eapi_is_deprecated from portage.localization import _ from portage.package.ebuild.config import config -from portage.versions import catpkgsplit +from portage.versions import catpkgsplit, _pkg_str if sys.hexversion >= 0x3000000: basestring = str @@ -51,9 +51,6 @@ def _getmaskingstatus(mycpv, settings, portdb, myrepo=None): 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: @@ -68,6 +65,13 @@ def _getmaskingstatus(mycpv, settings, portdb, myrepo=None): else: metadata["USE"] = "" + if not hasattr(mycpv, 'slot'): + try: + mycpv = _pkg_str(mycpv, slot=metadata['SLOT'], + repo=metadata.get('repository')) + except portage.exception.InvalidData: + raise ValueError(_("invalid CPV: %s") % mycpv) + rValue = [] # package.mask checking diff --git a/pym/portage/versions.py b/pym/portage/versions.py index ea8d5ae57..33c7159a5 100644 --- a/pym/portage/versions.py +++ b/pym/portage/versions.py @@ -339,10 +339,10 @@ class _pkg_str(_unicode): manually convert them to a plain unicode object first. """ - def __new__(cls, cpv, eapi=None): + def __new__(cls, cpv, slot=None, repo=None, eapi=None): return _unicode.__new__(cls, cpv) - def __init__(self, cpv, eapi=None): + def __init__(self, cpv, slot=None, repo=None, eapi=None): if not isinstance(cpv, _unicode): # Avoid TypeError from _unicode.__init__ with PyPy. cpv = _unicode_decode(cpv) @@ -353,6 +353,10 @@ class _pkg_str(_unicode): self.__dict__['cp'] = self.cpv_split[0] + '/' + self.cpv_split[1] # for match_from_list introspection self.__dict__['cpv'] = self + if slot is not None: + self.__dict__['slot'] = slot + if repo is not None: + self.__dict__['repo'] = repo def __setattr__(self, name, value): raise AttributeError("_pkg_str instances are immutable", -- 2.26.2