summaryrefslogtreecommitdiffstats
path: root/pym/portage/dbapi/bintree.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-06-04 14:40:11 -0700
committerZac Medico <zmedico@gentoo.org>2010-06-04 14:40:11 -0700
commitdcc31fb3482a4ae24b0ce58238e4444d01a6ad16 (patch)
treee4a024737e56dd1d63ba8162f1b2f758cab0da7d /pym/portage/dbapi/bintree.py
parent742c950219ac8796e324b8d3d31235e69661dbad (diff)
downloadportage-dcc31fb3482a4ae24b0ce58238e4444d01a6ad16.tar.gz
portage-dcc31fb3482a4ae24b0ce58238e4444d01a6ad16.tar.bz2
portage-dcc31fb3482a4ae24b0ce58238e4444d01a6ad16.zip
Split out a _pkgindex_cpv_map_latest_build() function.
Diffstat (limited to 'pym/portage/dbapi/bintree.py')
-rw-r--r--pym/portage/dbapi/bintree.py62
1 files changed, 36 insertions, 26 deletions
diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
index 680a6395a..080f9e5ff 100644
--- a/pym/portage/dbapi/bintree.py
+++ b/pym/portage/dbapi/bintree.py
@@ -159,6 +159,41 @@ class bindbapi(fakedbapi):
self.bintree.populate()
return fakedbapi.cpv_all(self)
+def _pkgindex_cpv_map_latest_build(pkgindex):
+ """
+ Given a PackageIndex instance, create a dict of cpv -> metadata map.
+ If multiple packages have identical CPV values, prefer the package
+ with latest BUILD_TIME value.
+ @param pkgindex: A PackageIndex instance.
+ @type pkgindex: PackageIndex
+ @rtype: dict
+ @returns: a dict containing entry for the give cpv.
+ """
+ cpv_map = {}
+
+ for d in pkgindex.packages:
+ cpv = d["CPV"]
+
+ btime = d.get('BUILD_TIME', '')
+ try:
+ btime = int(btime)
+ except ValueError:
+ btime = None
+
+ other_d = cpv_map.get(cpv)
+ if other_d is not None:
+ other_btime = other_d.get('BUILD_TIME', '')
+ try:
+ other_btime = int(other_btime)
+ except ValueError:
+ other_btime = None
+ if other_btime and (not btime or other_btime > btime):
+ continue
+
+ cpv_map[cpv] = d
+
+ return cpv_map
+
class binarytree(object):
"this tree scans for a list of all packages available in PKGDIR"
def __init__(self, root, pkgdir, virtual=None, settings=None):
@@ -777,33 +812,8 @@ class binarytree(object):
# The current user doesn't have permission to cache the
# file, but that's alright.
if pkgindex:
- self._remotepkgs = {}
-
# Organize remote package list as a cpv -> metadata map.
- # If multiple packages have identical CPV values, prefer
- # the package with latest BUILD_TIME value.
- remotepkgs = self._remotepkgs
- for d in pkgindex.packages:
- cpv = d["CPV"]
-
- btime = d.get('BUILD_TIME', '')
- try:
- btime = int(btime)
- except ValueError:
- btime = None
-
- other_d = remotepkgs.get(cpv)
- if other_d is not None:
- other_btime = other_d.get('BUILD_TIME', '')
- try:
- other_btime = int(other_btime)
- except ValueError:
- other_btime = None
- if other_btime and (not btime or other_btime > btime):
- continue
-
- remotepkgs[cpv] = d
-
+ self._remotepkgs = _pkgindex_cpv_map_latest_build(pkgindex)
self._remote_has_index = True
self._remote_base_uri = pkgindex.header.get("URI", base_url)
self.__remotepkgs = {}