_pkg_str: validate repo (move code from Package)
authorZac Medico <zmedico@gentoo.org>
Sun, 13 May 2012 23:40:29 +0000 (16:40 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 13 May 2012 23:40:29 +0000 (16:40 -0700)
pym/_emerge/Package.py
pym/portage/dbapi/__init__.py
pym/portage/dep/__init__.py
pym/portage/versions.py

index 84a2cbced419bc14287f6b9d6d8a6e7a390c68d8..c04fa1f8f398b1c42dc3ba49dc433ee8be02374a 100644 (file)
@@ -8,12 +8,10 @@ from portage import _encodings, _unicode_decode, _unicode_encode
 from portage.cache.mappings import slot_dict_class
 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
+       paren_enclose, _slot_re, _slot_separator, _repo_separator
+from portage.versions import _pkg_str, _unknown_repo
 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
 from _emerge.Task import Task
 
 if sys.hexversion >= 0x3000000:
@@ -58,12 +56,11 @@ 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.cpv = _pkg_str(self.cpv, slot=slot,
+                       repo=self.metadata.get('repository', ''))
                self.cp = self.cpv.cp
+               # sync metadata with validated repo (may be UNKNOWN_REPO)
+               self.metadata['repository'] = self.cpv.repo
                if (self.iuse.enabled or self.iuse.disabled) and \
                        not eapi_has_iuse_defaults(self.metadata["EAPI"]):
                        if not self.installed:
@@ -87,7 +84,7 @@ class Package(Task):
 
                self._hash_key = Package._gen_hash_key(cpv=self.cpv,
                        installed=self.installed, onlydeps=self.onlydeps,
-                       operation=self.operation, repo_name=repo,
+                       operation=self.operation, repo_name=self.cpv.repo,
                        root_config=self.root_config,
                        type_name=self.type_name)
                self._hash_value = hash(self._hash_key)
index 7a4c823ab726995de7342bec18f3cbd9eac56ecd..a1c5c567460706cfd1a5deebe18d4a9e6848197d 100644 (file)
@@ -160,8 +160,6 @@ class dbapi(object):
                        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
 
index 38382170ad511e72f7e67febef53b88db0c5ecdd..55ed4810ccb816b04d20ca2db83fa596eb863302 100644 (file)
@@ -43,7 +43,7 @@ from portage.eapi import eapi_has_slot_deps, eapi_has_src_uri_arrows, \
 from portage.exception import InvalidAtom, InvalidData, InvalidDependString
 from portage.localization import _
 from portage.versions import catpkgsplit, catsplit, \
-       pkgcmp, vercmp, ververify, _cp, _cpv, _pkg_str
+       vercmp, ververify, _cp, _cpv, _pkg_str, _unknown_repo
 import portage.cache.mappings
 
 if sys.hexversion >= 0x3000000:
@@ -54,8 +54,6 @@ if sys.hexversion >= 0x3000000:
 # stable keywords, make these warnings unconditional.
 _internal_warnings = False
 
-_unknown_repo = "__unknown__"
-
 def cpvequal(cpv1, cpv2):
        """
        
index 298b7aaca0e049b2a43c686afe2139905480d394..db14e998840ced7d03b1fe9196e596e9470439fa 100644 (file)
@@ -19,13 +19,16 @@ else:
 
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
-       'portage.util:cmp_sort_key'
+       'portage.repository.config:_gen_valid_repo',
+       'portage.util:cmp_sort_key',
 )
 from portage import _unicode_decode
 from portage.eapi import eapi_allows_dots_in_PN
 from portage.exception import InvalidData
 from portage.localization import _
 
+_unknown_repo = "__unknown__"
+
 # \w is [a-zA-Z0-9_]
 
 # 2.1.1 A category name may contain any of the characters [A-Za-z0-9+_.-].
@@ -347,6 +350,9 @@ class _pkg_str(_unicode):
                if slot is not None:
                        self.__dict__['slot'] = slot
                if repo is not None:
+                       repo = _gen_valid_repo(repo)
+                       if not repo:
+                               repo = _unknown_repo
                        self.__dict__['repo'] = repo
 
        def __setattr__(self, name, value):