Add lazy loading of virtuals in portage.do_vartree() for backward compatibility.
authorZac Medico <zmedico@gentoo.org>
Sat, 25 Mar 2006 13:57:45 +0000 (13:57 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 25 Mar 2006 13:57:45 +0000 (13:57 -0000)
svn path=/main/trunk/; revision=3004

pym/portage.py

index 5aca71a91573728ecc9ac2aaa2251189d5317686..3becb1b9bca3c9df7f0026bcd8c6e39b70a8c83b 100644 (file)
@@ -6574,9 +6574,29 @@ def getvirtuals(myroot):
        return settings.getvirtuals(myroot)
 
 def do_vartree(mysettings):
-       db["/"] = {"vartree":vartree("/")}
+       class LazyVirtualsDict(dict):
+               def __init__(self, myroot):
+                       super(LazyVirtualsDict, self).__init__()
+                       self.myroot = myroot
+                       self["virtuals"] = None
+               def __getitem__(self, key):
+                       if "virtuals" == key:
+                               if "virtuals" in self:
+                                       virtuals = super(LazyVirtualsDict, self).__getitem__("virtuals")
+                                       if virtuals is not None:
+                                               return virtuals
+                                       else:
+                                               global settings
+                                               virtuals = settings.getvirtuals(self.myroot)
+                                               self["virtuals"] = virtuals
+                                               return virtuals
+                       return super(LazyVirtualsDict, self).__getitem__(key)
+       global db, root
+       db["/"] = LazyVirtualsDict("/")
+       db["/"]["vartree"] = vartree("/")
        if root!="/":
-               db[root] = {"vartree":vartree(root)}
+               db[root] = LazyVirtualsDict(root)
+               db[root]["vartree"] = vartree(root)
        #We need to create the vartree first, then load our settings, and then set up our other trees
 
 usedefaults=settings.use_defs