summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-04-11 05:34:43 +0000
committerZac Medico <zmedico@gentoo.org>2006-04-11 05:34:43 +0000
commite3b0ef371b31e177f0bc4d2c441eb75e14a05d46 (patch)
treea62940b62e89c7069db2e54ce46d94321afa9673
parent10a15b0c45e9c6945b36c0d09d78edda059d4d72 (diff)
downloadportage-e3b0ef371b31e177f0bc4d2c441eb75e14a05d46.tar.gz
portage-e3b0ef371b31e177f0bc4d2c441eb75e14a05d46.tar.bz2
portage-e3b0ef371b31e177f0bc4d2c441eb75e14a05d46.zip
Implement lazy construction of global databases db[root]["porttree"] and db[root]["bintree"] and automatically populate
db[root]["bintree"] on access. svn path=/main/trunk/; revision=3127
-rw-r--r--pym/portage.py31
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():