diff options
-rw-r--r-- | pym/portage.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/pym/portage.py b/pym/portage.py index 0b815fed6..d58d9a968 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -6804,11 +6804,34 @@ if (secpass==2) and (not os.environ.has_key("SANDBOX_ACTIVE")): global_updates() #continue setting up other trees -db["/"]["porttree"] = portagetree("/") -db["/"]["bintree"] = binarytree("/", settings["PKGDIR"]) +class LazyDatabasesDict(dict): + """This class implements lazy construction of the global databases + db[root]["porttree"] and db[root]["bintree"].""" + def __init__(self, myroot, items): + dict.__init__(self) + self.update(items) + self.myroot = myroot + self.lazy_keys = ("porttree", "bintree") + for x in self.lazy_keys: + self[x] = None + def __getitem__(self, item_key): + if item_key in self.lazy_keys and item_key in self: + myvalue = dict.__getitem__(self, item_key) + if myvalue is None: + if "porttree" == item_key: + myvalue = portagetree(self.myroot) + elif "bintree" == item_key: + global settings + myvalue = binarytree(self.myroot, settings["PKGDIR"]) + # The binarytree likely needs to be populated now, so we + # do it now to make sure that all method calls are safe. + myvalue.populate() + return myvalue + return dict.__getitem__(self, item_key) + +db["/"] = LazyDatabasesDict("/", db["/"]) if root!="/": - db[root]["porttree"] = portagetree(root) - db[root]["bintree"] = binarytree(root, settings["PKGDIR"]) + db[root] = LazyDatabasesDict(root, db[root]) profileroots = [settings["PORTDIR"]+"/profiles/"] for x in settings["PORTDIR_OVERLAY"].split(): |