Add an initial_items parameter to the LazyItemsDict constructor in order to facilitat...
authorZac Medico <zmedico@gentoo.org>
Fri, 14 Apr 2006 06:30:52 +0000 (06:30 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 14 Apr 2006 06:30:52 +0000 (06:30 -0000)
svn path=/main/trunk/; revision=3143

pym/portage.py
pym/portage_util.py

index 4f8c9423c17bd6dcc49a5fe071ab6819f98b1653..547085c244580f8c8bf7c07577e3da2f7a031454 100644 (file)
@@ -1414,14 +1414,8 @@ class config:
                                                                global db, root
                                                                self._use = autouse(db[root]["vartree"], *self._pargs, **self._kwargs)
                                                        return self._use
-                                       if isinstance(self.configdict["auto"],
-                                               portage_util.LazyItemsDict):
-                                               lazy_values = self.configdict["auto"]
-                                       else:
-                                               lazy_values = portage_util.LazyItemsDict()
-                                               lazy_values.update(self.configdict["auto"])
-                                       lazy_values.addLazyItem("USE", LazyAutouse(use_cache=use_cache))
-                                       self.configdict["auto"] = lazy_values
+                                       self.configdict["auto"] = portage_util.LazyItemsDict(self.configdict["auto"])
+                                       self.configdict["auto"].addLazyItem("USE", LazyAutouse(use_cache=use_cache))
                                else:
                                        self.configdict["auto"]["USE"]=""
                        else:
index 6fd76090c21b35e9abc307bdd40e02151b1c1e83..cd69733ba735505180bb1e2c8072a4f33bbba6d8 100644 (file)
@@ -715,9 +715,13 @@ class LazyItemsDict(dict):
        """A mapping object that behaves like a standard dict except that it allows
        for lazy initialization of values via callable objects.  Lazy items can be
        overwritten and deleted just as normal items."""
-       def __init__(self):
+       def __init__(self, initial_items=None):
                dict.__init__(self)
                self.lazy_items = {}
+               if initial_items is not None:
+                       self.update(initial_items)
+                       if isinstance(initial_items, LazyItemsDict):
+                               self.lazy_items.update(initial_items.lazy_items)
        def addLazyItem(self, item_key, value_callable):
                """Add a lazy item for the given key.  When the item is requested,
                value_callable will be called with no arguments."""