public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/, pym/portage/dep/, pym/_emerge/
Date: Sun, 13 May 2012 08:36:41 +0000 (UTC)	[thread overview]
Message-ID: <1336898185.f31320b67c9f593a2a8592e1a4e547f5f641943a.zmedico@gentoo> (raw)

commit:     f31320b67c9f593a2a8592e1a4e547f5f641943a
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun May 13 08:36:25 2012 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun May 13 08:36:25 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=f31320b6

_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",)
 
 	metadata_keys = [
@@ -71,8 +71,8 @@ class Package(Task):
 					"IUSE contains defaults, but EAPI doesn't allow them")
 		self.slot_atom = portage.dep.Atom("%s%s%s" % (self.cp, _slot_separator, slot))
 		self.category, self.pf = portage.catsplit(self.cpv)
-		self.cpv_split = portage.catpkgsplit(self.cpv)
-		self.pv_split = self.cpv_split[1:]
+		self.cpv_split = self.cpv.cpv_split
+		self.version = self.cpv.version
 		if self.inherited is None:
 			self.inherited = frozenset()
 
@@ -532,28 +532,28 @@ class Package(Task):
 	def __lt__(self, other):
 		if other.cp != 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
 
 	def __le__(self, other):
 		if other.cp != 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
 
 	def __gt__(self, other):
 		if other.cp != 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
 
 	def __ge__(self, other):
 		if other.cp != 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
 

diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py
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=1):
 		raise NotImplementedError(self)
 
-	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 = {}
-			for cpv in cpv_list:
-				ver_map[cpv] = '-'.join(catpkgsplit(cpv)[2:])
-			def cmp_cpv(cpv1, cpv2):
-				return vercmp(ver_map[cpv1], ver_map[cpv2])
-			cpv_list.sort(key=cmp_sort_key(cmp_cpv))
+			cpv_list.sort(key=cmp_sort_key(dbapi._cmp_cpv))
 
 	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 @@
 
 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
 
 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 = cpv_getkey(mycpv)
+		if not hasattr(mycpv, 'cp'):
+			if metadata is None:
+				mycpv = _pkg_str(mycpv)
+			else:
+				mycpv = _pkg_str(mycpv, slot=metadata.get('SLOT'),
+					repo=metadata.get('repository'))
+		mycp = mycpv.cp
 		self.cpvdict[mycpv] = metadata
 		myslot = 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'] = cp
 		try:
 			self.__dict__['cpv'] = _pkg_str(cpv)
+			self.__dict__['version'] = self.cpv.version
 		except InvalidData:
 			# plain cp, wildcard, or something
 			self.__dict__['cpv'] = cpv
+			self.__dict__['version'] = None
 		self.__dict__['repo'] = repo
 		self.__dict__['slot'] = slot
 		self.__dict__['operator'] = op
@@ -2003,15 +2005,17 @@ def match_from_list(mydep, candidate_list):
 			mylist.append(x)
 
 	elif operator in [">", ">=", "<", "<="]:
-		mysplit = ["%s/%s" % (cat, pkg), ver, rev]
 		for x in candidate_list:
-			xs = getattr(x, "cpv_split", None)
-			if xs is None:
-				xs = catpkgsplit(remove_slot(x))
-			xcat, xpkg, xver, xrev = xs
-			xs = ["%s/%s" % (xcat, xpkg), xver, xrev]
+			if not hasattr(x, 'cp'):
+				try:
+					x = _pkg_str(remove_slot(x))
+				except InvalidData:
+					continue
+
+			if x.cp != mydep.cp:
+				continue
 			try:
-				result = pkgcmp(xs, mysplit)
+				result = vercmp(x.version, mydep.version)
 			except ValueError: # pkgcmp may return ValueError during int() conversion
 				writemsg(_("\nInvalid package name: %s\n") % x, noiselevel=-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'] = self.cpv_split[0] + '/' + self.cpv_split[1]
+		self.__dict__['version'] = "-".join(self.cpv_split[2:])
 		# for match_from_list introspection
 		self.__dict__['cpv'] = self
 		if slot is not None:



             reply	other threads:[~2012-05-13  8:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-13  8:36 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-09-22 22:05 [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/, pym/portage/dep/, pym/_emerge/ Zac Medico
2012-05-13 23:40 Zac Medico
2012-05-12  9:38 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1336898185.f31320b67c9f593a2a8592e1a4e547f5f641943a.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox