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:
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
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
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"]
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.
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 \