_pkg_str: add slot and repo attributes
authorZac Medico <zmedico@gentoo.org>
Sun, 13 May 2012 01:07:29 +0000 (18:07 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 13 May 2012 01:07:29 +0000 (18:07 -0700)
pym/_emerge/Package.py
pym/portage/dbapi/__init__.py
pym/portage/package/ebuild/_config/KeywordsManager.py
pym/portage/package/ebuild/_config/LicenseManager.py
pym/portage/package/ebuild/_config/UseManager.py
pym/portage/package/ebuild/_config/helper.py
pym/portage/package/ebuild/config.py
pym/portage/package/ebuild/getmaskingstatus.py
pym/portage/versions.py

index ec0c3f6d44b9c94b11c2921ed78db0f8a4ea6d69..69739acc40ed5a3951707357c7b35a93e5e13752 100644 (file)
@@ -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()
index 96e85cecd92f55cc87f4d64023ebafdfacdb9563..a835d4de88289b3e83b18ea708ffaf3687807b73 100644 (file)
@@ -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
index 2f9f7b30557324450155008f4351d5340f24d2e9..0c613ce04f9cd294cfb8e06454f1a88940f44457 100644 (file)
@@ -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)
index effd55be3f262de6efe7d3fd9c57c417821ae338..f76e7e2feec8e9749f23811569187bb40a1d4872 100644 (file)
@@ -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:
index 0506af019948ad2612cb3962a76240877a6dde40..e1ec7f4a01f2f6f775e9bbb628d5e73ac1ffae32 100644 (file)
@@ -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 = []
index 4f467818756a52e5cf0b7408b75d7bad838468b3..ee0c090a0436408c00744b49317bb812676974f7 100644 (file)
@@ -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 = []
index 24342080f037af2c2c1e471fcb9b0dcfb78199e0..aa4a62ea286da7c9b5597143de470156a3f8fc47 100644 (file)
@@ -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:
index b89fbf53b8d2ad90c0c935beae895d366cf41188..9bf605db6c02ecd75592383a045eb14d0bee68a5 100644 (file)
@@ -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
index ea8d5ae57f3e1b7e3d3fd58f863f1787cc1e235d..33c7159a52498cb0fe65432832ec53fd57210c15 100644 (file)
@@ -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",