From 7df38f87fddbcf7c9ac23e2da801c4c75bf3c6ff Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 28 Dec 2007 18:20:29 +0000 Subject: [PATCH] Make dep_expand() stop relying on having a categories list: * Create and use a dbapi.categories property that is automatically generated from dbapi.cp_all(). * Make mutable dbapi instances delete the invalidate the cached categories when they need to be regenerated. svn path=/main/trunk/; revision=9080 --- pym/portage/__init__.py | 4 ++-- pym/portage/dbapi/__init__.py | 17 +++++++++++++++++ pym/portage/dbapi/vartree.py | 13 +++++++++---- pym/portage/dbapi/virtual.py | 2 ++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index d79771560..0b5ddfc52 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -5567,8 +5567,8 @@ def cpv_expand(mycpv, mydb=None, use_cache=1, settings=None): myp=mycpv mykey=None matches=[] - if mydb: - for x in settings.categories: + if mydb and hasattr(mydb, "categories"): + for x in mydb.categories: if mydb.cp_list(x+"/"+myp,use_cache=use_cache): matches.append(x+"/"+myp) if len(matches) > 1: diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py index 0e473ddd1..d41a7fba3 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -18,6 +18,23 @@ class dbapi(object): def __init__(self): pass + @property + def categories(self): + """ + Use self.cp_all() to generate a category list. Mutable instances + can delete the self._categories attribute in cases when the cached + categories become invalid and need to be regenerated. + """ + if hasattr(self, "_categories"): + return self._categories + categories = set() + cat_pattern = re.compile(r'(.*)/.*') + for cp in self.cp_all(): + categories.add(cat_pattern.match(cp).group(1)) + self._categories = list(categories) + self._categories.sort() + return self._categories + def close_caches(self): pass diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index ba45330b6..bfed2f798 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -166,6 +166,11 @@ class LibraryPackageMap(object): class vardbapi(dbapi): def __init__(self, root, categories=None, settings=None, vartree=None): + """ + The categories parameter is unused since the dbapi class + now has a categories property that is generated from the + available packages. + """ self.root = root[:] #cache for category directory mtimes @@ -181,9 +186,6 @@ class vardbapi(dbapi): if settings is None: from portage import settings self.settings = settings - # The categories list is now automatically generated - # from a regular expression. - self.categories = None if vartree is None: from portage import db vartree = db[root]["vartree"] @@ -1071,7 +1073,8 @@ class dblink(object): The caller must ensure that lockdb() and unlockdb() are called before and after this method. """ - + if hasattr(self.vartree.dbapi, "_categories"): + del self.vartree.dbapi._categories # When others_in_slot is supplied, the security check has already been # done for this slot, so it shouldn't be repeated until the next # replacement or unmerge operation. @@ -2425,6 +2428,8 @@ class dblink(object): we won't be able to later if they get unmerged (happens when namespace changes). """ + if hasattr(self.vartree.dbapi, "_categories"): + del self.vartree.dbapi._categories if self.myroot == "/" and \ "sys-apps" == self.cat and \ "portage" == pkgsplit(self.pkg)[0] and \ diff --git a/pym/portage/dbapi/virtual.py b/pym/portage/dbapi/virtual.py index fe9356212..3d5472f1e 100644 --- a/pym/portage/dbapi/virtual.py +++ b/pym/portage/dbapi/virtual.py @@ -26,6 +26,8 @@ class fakedbapi(dbapi): self._match_cache = {} def _clear_cache(self): + if hasattr(self, "_categories"): + del self._categories if self._match_cache: self._match_cache = {} -- 2.26.2