From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1ST8mZ-00074z-QD for garchives@archives.gentoo.org; Sat, 12 May 2012 09:38:36 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 72376E09BB; Sat, 12 May 2012 09:38:13 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 33D80E09BB for ; Sat, 12 May 2012 09:38:13 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5DE0264204 for ; Sat, 12 May 2012 09:38:12 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 26609E542D for ; Sat, 12 May 2012 09:38:11 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1336815151.f75f2f3169a63e8b39cea1087e099e176d90e20e.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/, pym/portage/dep/, pym/_emerge/ X-VCS-Repository: proj/portage X-VCS-Files: pym/_emerge/BlockerCache.py pym/portage/dbapi/bintree.py pym/portage/dbapi/porttree.py pym/portage/dbapi/vartree.py pym/portage/dep/__init__.py pym/portage/versions.py X-VCS-Directories: pym/portage/dbapi/ pym/portage/ pym/portage/dep/ pym/_emerge/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: f75f2f3169a63e8b39cea1087e099e176d90e20e X-VCS-Branch: master Date: Sat, 12 May 2012 09:38:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 344ed6b1-9264-418d-9014-b3ba4abc62f9 X-Archives-Hash: 275c7552bd4a27edd90ae9a28f4a5f9b commit: f75f2f3169a63e8b39cea1087e099e176d90e20e Author: Zac Medico gentoo org> AuthorDate: Sat May 12 09:25:39 2012 +0000 Commit: Zac Medico gentoo org> CommitDate: Sat May 12 09:32:31 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3Df75f2f31 Add a _pkg_str class to cache catpkgsplit results This will compensate for the removal of the catpkgsplit cache in commit 68888b0450b1967cb70673a5f06b04c167ef879c. --- pym/_emerge/BlockerCache.py | 7 ++++- pym/portage/dbapi/bintree.py | 6 +++- pym/portage/dbapi/porttree.py | 4 +- pym/portage/dbapi/vartree.py | 12 +++++++--- pym/portage/dep/__init__.py | 8 +++++- pym/portage/versions.py | 44 +++++++++++++++++++++++++++++++++++= +++++- 6 files changed, 68 insertions(+), 13 deletions(-) diff --git a/pym/_emerge/BlockerCache.py b/pym/_emerge/BlockerCache.py index 06598a4..3ec63ce 100644 --- a/pym/_emerge/BlockerCache.py +++ b/pym/_emerge/BlockerCache.py @@ -1,4 +1,4 @@ -# Copyright 1999-2011 Gentoo Foundation +# Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 =20 import errno @@ -16,6 +16,9 @@ except ImportError: if sys.hexversion >=3D 0x3000000: basestring =3D str long =3D int + _unicode =3D str +else: + _unicode =3D unicode =20 class BlockerCache(portage.cache.mappings.MutableMapping): """This caches blockers of installed packages so that dep_check does no= t @@ -159,7 +162,7 @@ class BlockerCache(portage.cache.mappings.MutableMapp= ing): @param blocker_data: An object with counter and atoms attributes. @type blocker_data: BlockerData """ - self._cache_data["blockers"][cpv] =3D \ + self._cache_data["blockers"][_unicode(cpv)] =3D \ (blocker_data.counter, tuple(str(x) for x in blocker_data.atoms)) self._modified.add(cpv) =20 diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index 810163d..52b85b8 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -16,7 +16,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.util:atomic_ofstream,ensure_dirs,normalize_path,' + \ 'writemsg,writemsg_stdout', 'portage.util.listdir:listdir', - 'portage.versions:best,catpkgsplit,catsplit', + 'portage.versions:best,catpkgsplit,catsplit,_pkg_str', ) =20 from portage.cache.mappings import slot_dict_class @@ -236,7 +236,7 @@ def _pkgindex_cpv_map_latest_build(pkgindex): if other_btime and (not btime or other_btime > btime): continue =20 - cpv_map[cpv] =3D d + cpv_map[_pkg_str(cpv)] =3D d =20 return cpv_map =20 @@ -658,6 +658,7 @@ class binarytree(object): if mycpv in pkg_paths: # discard duplicates (All/ is preferred) continue + mycpv =3D _pkg_str(mycpv) pkg_paths[mycpv] =3D mypath # update the path if the package has been moved oldpath =3D d.get("PATH") @@ -733,6 +734,7 @@ class binarytree(object): (mycpv, self.settings["PORTAGE_CONFIGROOT"]), noiselevel=3D-1) continue + mycpv =3D _pkg_str(mycpv) pkg_paths[mycpv] =3D mypath self.dbapi.cpv_inject(mycpv) update_pkgindex =3D True diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.p= y index f348a15..663b62d 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -14,7 +14,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.package.ebuild.doebuild:doebuild', 'portage.util:ensure_dirs,shlex_split,writemsg,writemsg_level', 'portage.util.listdir:listdir', - 'portage.versions:best,catpkgsplit,_pkgsplit@pkgsplit,ver_regexp', + 'portage.versions:best,catpkgsplit,_pkgsplit@pkgsplit,ver_regexp,_pkg_s= tr', ) =20 from portage.cache import volatile @@ -708,7 +708,7 @@ class portdbapi(dbapi): writemsg(_("\nInvalid ebuild version: %s\n") % \ os.path.join(oroot, mycp, x), noiselevel=3D-1) continue - d[mysplit[0]+"/"+pf] =3D None + d[_pkg_str(mysplit[0]+"/"+pf)] =3D None if invalid_category and d: writemsg(_("\n!!! '%s' has a category that is not listed in " \ "%setc/portage/categories\n") % \ diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 158fc4a..fe352c5 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -31,7 +31,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.util._dyn_libs.PreservedLibsRegistry:PreservedLibsRegistry', 'portage.util._dyn_libs.LinkageMapELF:LinkageMapELF@LinkageMap', 'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,pkgcmp,' + \ - '_pkgsplit@pkgsplit', + '_pkgsplit@pkgsplit,_pkg_str', 'subprocess', 'tarfile', ) @@ -87,6 +87,9 @@ except ImportError: if sys.hexversion >=3D 0x3000000: basestring =3D str long =3D int + _unicode =3D str +else: + _unicode =3D unicode =20 class vardbapi(dbapi): =20 @@ -386,7 +389,7 @@ class vardbapi(dbapi): continue if len(mysplit) > 1: if ps[0] =3D=3D mysplit[1]: - returnme.append(mysplit[0]+"/"+x) + returnme.append(_pkg_str(mysplit[0]+"/"+x)) self._cpv_sort_ascending(returnme) if use_cache: self.cpcache[mycp] =3D [mystat, returnme[:]] @@ -680,7 +683,8 @@ class vardbapi(dbapi): cache_data.update(metadata) for aux_key in cache_these: cache_data[aux_key] =3D mydata[aux_key] - self._aux_cache["packages"][mycpv] =3D (mydir_mtime, cache_data) + self._aux_cache["packages"][_unicode(mycpv)] =3D \ + (mydir_mtime, cache_data) self._aux_cache["modified"].add(mycpv) =20 if _slot_re.match(mydata['SLOT']) is None: @@ -1059,7 +1063,7 @@ class vardbapi(dbapi): counter =3D int(counter) except ValueError: counter =3D 0 - return (cpv, counter, mtime) + return (_unicode(cpv), counter, mtime) =20 class _owners_db(object): =20 diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index 2e3444d..de8d1c4 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -43,7 +43,7 @@ from portage.eapi import eapi_has_slot_deps, eapi_has_s= rc_uri_arrows, \ from portage.exception import InvalidAtom, InvalidData, InvalidDependStr= ing from portage.localization import _ from portage.versions import catpkgsplit, catsplit, \ - pkgcmp, vercmp, ververify, _cp, _cpv + pkgcmp, vercmp, ververify, _cp, _cpv, _pkg_str import portage.cache.mappings =20 if sys.hexversion >=3D 0x3000000: @@ -1137,7 +1137,11 @@ class Atom(_atom_base): else: raise AssertionError(_("required group not found in atom: '%s'") % se= lf) self.__dict__['cp'] =3D cp - self.__dict__['cpv'] =3D cpv + try: + self.__dict__['cpv'] =3D _pkg_str(cpv) + except InvalidData: + # plain cp, wildcard, or something + self.__dict__['cpv'] =3D cpv self.__dict__['repo'] =3D repo self.__dict__['slot'] =3D slot self.__dict__['operator'] =3D op diff --git a/pym/portage/versions.py b/pym/portage/versions.py index e2761b5..de2fe70 100644 --- a/pym/portage/versions.py +++ b/pym/portage/versions.py @@ -9,13 +9,21 @@ __all__ =3D [ ] =20 import re +import sys import warnings =20 +if sys.hexversion < 0x3000000: + _unicode =3D unicode +else: + _unicode =3D str + import portage portage.proxy.lazyimport.lazyimport(globals(), '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 _ =20 # \w is [a-zA-Z0-9_] @@ -303,7 +311,10 @@ def catpkgsplit(mydata, silent=3D1, eapi=3DNone): 2. If cat is not specificed in mydata, cat will be "null" 3. if rev does not exist it will be '-r0' """ - + try: + return mydata.cpv_split + except AttributeError: + pass mysplit =3D mydata.split('/', 1) p_split=3DNone if len(mysplit)=3D=3D1: @@ -318,6 +329,33 @@ def catpkgsplit(mydata, silent=3D1, eapi=3DNone): retval =3D (cat, p_split[0], p_split[1], p_split[2]) return retval =20 +class _pkg_str(_unicode): + """ + This class represents a cpv. It inherits from str (unicode in python2) = and + has attributes that cache results for use by functions like catpkgsplit= and + cpv_getkey which are called frequently (especially in match_from_list). + Instances are typically created in dbapi.cp_list() or the Atom contruct= or, + and propagate from there. Generally, code that pickles these objects wi= ll + manually convert them to a plain unicode object first. + """ + + def __new__(cls, cpv, eapi=3DNone): + return _unicode.__new__(cls, cpv) + + def __init__(self, cpv, eapi=3DNone): + if not isinstance(cpv, _unicode): + # Avoid TypeError from _unicode.__init__ with PyPy. + cpv =3D _unicode_decode(cpv) + _unicode.__init__(cpv) + self.__dict__['cpv_split'] =3D catpkgsplit(cpv, eapi=3Deapi) + if self.cpv_split is None: + raise InvalidData(cpv) + self.__dict__['cp'] =3D self.cpv_split[0] + '/' + self.cpv_split[1] + + def __setattr__(self, name, value): + raise AttributeError("_pkg_str instances are immutable", + self.__class__, name, value) + def pkgsplit(mypkg, silent=3D1, eapi=3DNone): """ @param mypkg: either a pv or cpv @@ -337,6 +375,10 @@ def pkgsplit(mypkg, silent=3D1, eapi=3DNone): =20 def cpv_getkey(mycpv, eapi=3DNone): """Calls catpkgsplit on a cpv and returns only the cp.""" + try: + return mycpv.cp + except AttributeError: + pass mysplit =3D catpkgsplit(mycpv, eapi=3Deapi) if mysplit is not None: return mysplit[0] + '/' + mysplit[1]