summaryrefslogtreecommitdiffstats
path: root/pym/portage/dbapi
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2012-05-13 01:36:25 -0700
committerZac Medico <zmedico@gentoo.org>2012-05-13 01:36:25 -0700
commitf31320b67c9f593a2a8592e1a4e547f5f641943a (patch)
treeb5fbe65ded8a1ffc75ccf5f80c50e0872ad6972a /pym/portage/dbapi
parent0903cf2a1544d970b286a3e7e1f3276daa4eab9c (diff)
downloadportage-f31320b67c9f593a2a8592e1a4e547f5f641943a.tar.gz
portage-f31320b67c9f593a2a8592e1a4e547f5f641943a.tar.bz2
portage-f31320b67c9f593a2a8592e1a4e547f5f641943a.zip
_pkg_str: add version attribute for comparisons
This attribute can be passed directly into vercmp, avoiding the need to generate this string many times.
Diffstat (limited to 'pym/portage/dbapi')
-rw-r--r--pym/portage/dbapi/__init__.py14
-rw-r--r--pym/portage/dbapi/virtual.py10
2 files changed, 15 insertions, 9 deletions
diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py
index a835d4de8..7a4c823ab 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 84b6b9367..da15983ee 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: