diff options
author | Zac Medico <zmedico@gentoo.org> | 2008-04-07 22:12:04 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2008-04-07 22:12:04 +0000 |
commit | 2527a0bc8f3fc9be217e0ab5b31468d2b36718f6 (patch) | |
tree | 55051cc2030ba83675eecf9719c009d1a7de8a33 /pym/portage | |
parent | 8b0e7e592421a32bbc1740aac7f5c428fa6f5944 (diff) | |
download | portage-2527a0bc8f3fc9be217e0ab5b31468d2b36718f6.tar.gz portage-2527a0bc8f3fc9be217e0ab5b31468d2b36718f6.tar.bz2 portage-2527a0bc8f3fc9be217e0ab5b31468d2b36718f6.zip |
* Optimize metadata caching in pordbapi and bindbapi so that cache is
never pulled for the same package twice.
* Cache a Package instances constructed during package selection
and reuse them during later package selections.
svn path=/main/trunk/; revision=9741
Diffstat (limited to 'pym/portage')
-rw-r--r-- | pym/portage/dbapi/__init__.py | 4 | ||||
-rw-r--r-- | pym/portage/dbapi/bintree.py | 24 | ||||
-rw-r--r-- | pym/portage/dbapi/porttree.py | 15 | ||||
-rw-r--r-- | pym/portage/getbinpkg.py | 9 |
4 files changed, 40 insertions, 12 deletions
diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py index cd3208d50..1431c1074 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -8,7 +8,7 @@ from portage.dep import dep_getslot, dep_getkey, match_from_list from portage.locks import unlockfile from portage.output import red from portage.util import writemsg -from portage import dep_expand +from portage import auxdbkeys, dep_expand from portage.versions import catpkgsplit, catsplit, pkgcmp @@ -16,6 +16,8 @@ class dbapi(object): _category_re = re.compile(r'^\w[-.+\w]*$') _pkg_dir_name_re = re.compile(r'^\w[-+\w]*$') _categories = None + _known_keys = frozenset(x for x in auxdbkeys + if not x.startswith("UNUSED_0")) def __init__(self): pass diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index 6b7e346d8..d2b499ba1 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -19,6 +19,8 @@ import re from itertools import izip class bindbapi(fakedbapi): + _known_keys = frozenset(list(fakedbapi._known_keys) + \ + ["CHOST", "repository", "USE"]) def __init__(self, mybintree=None, **kwargs): fakedbapi.__init__(self, **kwargs) self.bintree = mybintree @@ -27,8 +29,9 @@ class bindbapi(fakedbapi): self.cpdict={} # Selectively cache metadata in order to optimize dep matching. self._aux_cache_keys = set( - ["CHOST", "EAPI", "IUSE", "KEYWORDS", - "LICENSE", "PROVIDE", "SLOT", "USE"]) + ["CHOST", "DEPEND", "EAPI", "IUSE", "KEYWORDS", + "LICENSE", "PDEPEND", "PROVIDE", + "RDEPEND", "repository", "RESTRICT", "SLOT", "USE"]) self._aux_cache = {} def match(self, *pargs, **kwargs): @@ -40,10 +43,11 @@ class bindbapi(fakedbapi): if self.bintree and not self.bintree.populated: self.bintree.populate() cache_me = False - if not set(wants).difference(self._aux_cache_keys): + if not self._known_keys.intersection( + wants).difference(self._aux_cache_keys): aux_cache = self._aux_cache.get(mycpv) if aux_cache is not None: - return [aux_cache[x] for x in wants] + return [aux_cache.get(x, "") for x in wants] cache_me = True mysplit = mycpv.split("/") mylist = [] @@ -148,21 +152,28 @@ class binarytree(object): self._pkgindex_aux_keys = \ ["CHOST", "DEPEND", "DESCRIPTION", "EAPI", "IUSE", "KEYWORDS", "LICENSE", "PDEPEND", - "PROVIDE", "RDEPEND", "SLOT", "USE"] + "PROVIDE", "RDEPEND", "repository", "SLOT", "USE"] self._pkgindex_aux_keys = list(self._pkgindex_aux_keys) self._pkgindex_header_keys = set(["ACCEPT_KEYWORDS", "CBUILD", "CHOST", "CONFIG_PROTECT", "CONFIG_PROTECT_MASK", "FEATURES", "GENTOO_MIRRORS", "INSTALL_MASK", "SYNC", "USE"]) self._pkgindex_default_pkg_data = { + "DEPEND" : "", "EAPI" : "0", "IUSE" : "", "KEYWORDS": "", "LICENSE" : "", + "PDEPEND" : "", "PROVIDE" : "", + "RDEPEND" : "", + "RESTRICT": "", "SLOT" : "0", "USE" : "" } - self._pkgindex_inherited_keys = ["CHOST"] + self._pkgindex_inherited_keys = ["CHOST", "repository"] + self._pkgindex_default_header_data = { + "repository":"" + } def move_ent(self, mylist): if not self.populated: @@ -798,6 +809,7 @@ class binarytree(object): def _new_pkgindex(self): return portage.getbinpkg.PackageIndex( + default_header_data=self._pkgindex_default_header_data, default_pkg_data=self._pkgindex_default_pkg_data, inherited_keys=self._pkgindex_inherited_keys) diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index de5a03bfe..532530131 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -83,11 +83,13 @@ class portdbapi(dbapi): self.porttrees = [self.porttree_root] + \ [os.path.realpath(t) for t in self.mysettings["PORTDIR_OVERLAY"].split()] self.treemap = {} + self._repository_map = {} for path in self.porttrees: repo_name_path = os.path.join(path, REPO_NAME_LOC) try: repo_name = open(repo_name_path, 'r').readline().strip() self.treemap[repo_name] = path + self._repository_map[path] = repo_name except (OSError,IOError): # warn about missing repo_name at some other time, since we # don't want to see a warning every time the portage module is @@ -116,7 +118,9 @@ class portdbapi(dbapi): self.depcachedir, x, filtered_auxdbkeys, gid=portage_gid) # Selectively cache metadata in order to optimize dep matching. self._aux_cache_keys = set( - ["EAPI", "IUSE", "KEYWORDS", "LICENSE", "PROVIDE", "SLOT"]) + ["DEPEND", "EAPI", "IUSE", "KEYWORDS", "LICENSE", + "PDEPEND", "PROVIDE", "RDEPEND", "repository", + "RESTRICT", "SLOT"]) self._aux_cache = {} self._broken_ebuilds = set() @@ -208,10 +212,11 @@ class portdbapi(dbapi): cache_me = False if not mytree: cache_me = True - if not mytree and not set(mylist).difference(self._aux_cache_keys): + if not mytree and not self._known_keys.intersection( + mylist).difference(self._aux_cache_keys): aux_cache = self._aux_cache.get(mycpv) if aux_cache is not None: - return [aux_cache[x] for x in mylist] + return [aux_cache.get(x, "") for x in mylist] cache_me = True global auxdbkeys, auxdbkeylen cat,pkg = mycpv.split("/", 1) @@ -335,6 +340,10 @@ class portdbapi(dbapi): if not mydata.setdefault("EAPI", "0"): mydata["EAPI"] = "0" + # do we have a origin repository name for the current package + mydata["repository"] = self._repository_map.get( + os.path.sep.join(myebuild.split(os.path.sep)[:-3]), "") + #finally, we look at our internal cache entry and return the requested data. returnme = [] for x in mylist: diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index 147007659..376767957 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -667,10 +667,14 @@ def _cmp_cpv(d1, d2): class PackageIndex(object): - def __init__(self, default_pkg_data=None, inherited_keys=None): + def __init__(self, default_header_data=None, default_pkg_data=None, + inherited_keys=None): + self._default_header_data = default_header_data self._default_pkg_data = default_pkg_data self._inherited_keys = inherited_keys self.header = {} + if self._default_header_data: + self.header.update(self._default_header_data) self.packages = [] self.modified = True @@ -725,7 +729,8 @@ class PackageIndex(object): self.header["PACKAGES"] = str(len(self.packages)) keys = self.header.keys() keys.sort() - self._writepkgindex(pkgfile, [(k, self.header[k]) for k in keys]) + self._writepkgindex(pkgfile, [(k, self.header[k]) \ + for k in keys if self.header[k]]) for metadata in sorted(self.packages, _cmp_cpv): metadata = metadata.copy() cpv = metadata["CPV"] |