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 1STUIS-0004jg-TS for garchives@archives.gentoo.org; Sun, 13 May 2012 08:36:57 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3729BE0833; Sun, 13 May 2012 08:36:44 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id ED2BEE0833 for ; Sun, 13 May 2012 08:36:43 +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 028B41B4037 for ; Sun, 13 May 2012 08:36:43 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id B70C1E5429 for ; Sun, 13 May 2012 08:36:41 +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: <1336898185.f31320b67c9f593a2a8592e1a4e547f5f641943a.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/Package.py pym/portage/dbapi/__init__.py pym/portage/dbapi/virtual.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: f31320b67c9f593a2a8592e1a4e547f5f641943a X-VCS-Branch: master Date: Sun, 13 May 2012 08:36:41 +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: b83791ac-c468-46d6-8ce9-a10c0ee7b158 X-Archives-Hash: 976c5701a596f95d566eb03c1fbb7a28 commit: f31320b67c9f593a2a8592e1a4e547f5f641943a Author: Zac Medico gentoo org> AuthorDate: Sun May 13 08:36:25 2012 +0000 Commit: Zac Medico gentoo org> CommitDate: Sun May 13 08:36:25 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3Df31320b6 _pkg_str: add version attribute for comparisons This attribute can be passed directly into vercmp, avoiding the need to generate this string many times. --- pym/_emerge/Package.py | 14 +++++++------- pym/portage/dbapi/__init__.py | 14 +++++++------- pym/portage/dbapi/virtual.py | 10 ++++++++-- pym/portage/dep/__init__.py | 18 +++++++++++------- pym/portage/versions.py | 1 + 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py index 69739ac..84a2cbc 100644 --- a/pym/_emerge/Package.py +++ b/pym/_emerge/Package.py @@ -28,7 +28,7 @@ class Package(Task): "root_config", "type_name", "category", "counter", "cp", "cpv_split", "inherited", "invalid", "iuse", "masks", "mtime", - "pf", "pv_split", "root", "slot", "slot_atom", "visible",) + \ + "pf", "root", "slot", "slot_atom", "version", "visible",) + \ ("_raw_metadata", "_use",) =20 metadata_keys =3D [ @@ -71,8 +71,8 @@ class Package(Task): "IUSE contains defaults, but EAPI doesn't allow them") self.slot_atom =3D portage.dep.Atom("%s%s%s" % (self.cp, _slot_separat= or, slot)) self.category, self.pf =3D portage.catsplit(self.cpv) - self.cpv_split =3D portage.catpkgsplit(self.cpv) - self.pv_split =3D self.cpv_split[1:] + self.cpv_split =3D self.cpv.cpv_split + self.version =3D self.cpv.version if self.inherited is None: self.inherited =3D frozenset() =20 @@ -532,28 +532,28 @@ class Package(Task): def __lt__(self, other): if other.cp !=3D self.cp: return False - if portage.pkgcmp(self.pv_split, other.pv_split) < 0: + if portage.vercmp(self.version, other.version) < 0: return True return False =20 def __le__(self, other): if other.cp !=3D self.cp: return False - if portage.pkgcmp(self.pv_split, other.pv_split) <=3D 0: + if portage.vercmp(self.version, other.version) <=3D 0: return True return False =20 def __gt__(self, other): if other.cp !=3D self.cp: return False - if portage.pkgcmp(self.pv_split, other.pv_split) > 0: + if portage.vercmp(self.version, other.version) > 0: return True return False =20 def __ge__(self, other): if other.cp !=3D self.cp: return False - if portage.pkgcmp(self.pv_split, other.pv_split) >=3D 0: + if portage.vercmp(self.version, other.version) >=3D 0: return True return False =20 diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.p= y index a835d4d..7a4c823 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -46,7 +46,12 @@ class dbapi(object): def cp_list(self, cp, use_cache=3D1): raise NotImplementedError(self) =20 - def _cpv_sort_ascending(self, cpv_list): + @staticmethod + def _cmp_cpv(cpv1, cpv2): + return vercmp(cpv1.version, cpv2.version) + + @staticmethod + def _cpv_sort_ascending(cpv_list): """ Use this to sort self.cp_list() results in ascending order. It sorts in place and returns None. @@ -55,12 +60,7 @@ class dbapi(object): # If the cpv includes explicit -r0, it has to be preserved # for consistency in findname and aux_get calls, so use a # dict to map strings back to their original values. - ver_map =3D {} - for cpv in cpv_list: - ver_map[cpv] =3D '-'.join(catpkgsplit(cpv)[2:]) - def cmp_cpv(cpv1, cpv2): - return vercmp(ver_map[cpv1], ver_map[cpv2]) - cpv_list.sort(key=3Dcmp_sort_key(cmp_cpv)) + cpv_list.sort(key=3Dcmp_sort_key(dbapi._cmp_cpv)) =20 def cpv_all(self): """Return all CPVs in the db diff --git a/pym/portage/dbapi/virtual.py b/pym/portage/dbapi/virtual.py index 84b6b93..da15983 100644 --- a/pym/portage/dbapi/virtual.py +++ b/pym/portage/dbapi/virtual.py @@ -4,7 +4,7 @@ =20 from portage.dbapi import dbapi from portage.dbapi.dep_expand import dep_expand -from portage import cpv_getkey +from portage.versions import cpv_getkey, _pkg_str =20 class fakedbapi(dbapi): """A fake dbapi that allows consumers to inject/remove packages to/from= it @@ -74,7 +74,13 @@ class fakedbapi(dbapi): @param metadata: dict """ self._clear_cache() - mycp =3D cpv_getkey(mycpv) + if not hasattr(mycpv, 'cp'): + if metadata is None: + mycpv =3D _pkg_str(mycpv) + else: + mycpv =3D _pkg_str(mycpv, slot=3Dmetadata.get('SLOT'), + repo=3Dmetadata.get('repository')) + mycp =3D mycpv.cp self.cpvdict[mycpv] =3D metadata myslot =3D None if self._exclusive_slots and metadata: diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index d4888e0..240e223 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -1141,9 +1141,11 @@ class Atom(_atom_base): self.__dict__['cp'] =3D cp try: self.__dict__['cpv'] =3D _pkg_str(cpv) + self.__dict__['version'] =3D self.cpv.version except InvalidData: # plain cp, wildcard, or something self.__dict__['cpv'] =3D cpv + self.__dict__['version'] =3D None self.__dict__['repo'] =3D repo self.__dict__['slot'] =3D slot self.__dict__['operator'] =3D op @@ -2003,15 +2005,17 @@ def match_from_list(mydep, candidate_list): mylist.append(x) =20 elif operator in [">", ">=3D", "<", "<=3D"]: - mysplit =3D ["%s/%s" % (cat, pkg), ver, rev] for x in candidate_list: - xs =3D getattr(x, "cpv_split", None) - if xs is None: - xs =3D catpkgsplit(remove_slot(x)) - xcat, xpkg, xver, xrev =3D xs - xs =3D ["%s/%s" % (xcat, xpkg), xver, xrev] + if not hasattr(x, 'cp'): + try: + x =3D _pkg_str(remove_slot(x)) + except InvalidData: + continue + + if x.cp !=3D mydep.cp: + continue try: - result =3D pkgcmp(xs, mysplit) + result =3D vercmp(x.version, mydep.version) except ValueError: # pkgcmp may return ValueError during int() conver= sion writemsg(_("\nInvalid package name: %s\n") % x, noiselevel=3D-1) raise diff --git a/pym/portage/versions.py b/pym/portage/versions.py index 33c7159..35385e4 100644 --- a/pym/portage/versions.py +++ b/pym/portage/versions.py @@ -351,6 +351,7 @@ class _pkg_str(_unicode): if self.cpv_split is None: raise InvalidData(cpv) self.__dict__['cp'] =3D self.cpv_split[0] + '/' + self.cpv_split[1] + self.__dict__['version'] =3D "-".join(self.cpv_split[2:]) # for match_from_list introspection self.__dict__['cpv'] =3D self if slot is not None: