From b5f4edad3cd0ffc85bcef6ae9ed0f74cf878881d Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 25 Mar 2006 13:57:45 +0000 Subject: Add lazy loading of virtuals in portage.do_vartree() for backward compatibility. svn path=/main/trunk/; revision=3004 --- pym/portage.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'pym') diff --git a/pym/portage.py b/pym/portage.py index 5aca71a91..3becb1b9b 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -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 -- cgit v1.2.3-1-g7c22