Also use a separate proxy type for portage.mtimedb since it's independent
authorZac Medico <zmedico@gentoo.org>
Thu, 26 Jun 2008 06:43:47 +0000 (06:43 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 26 Jun 2008 06:43:47 +0000 (06:43 -0000)
from the portdb and settings.

svn path=/main/trunk/; revision=10800

pym/portage/__init__.py

index bcb2b7afbd425063ef03f2825cc0d9cfce8deca5..516be638d6d54797cc9fb09d8135b3183d29bd15 100644 (file)
@@ -6930,11 +6930,31 @@ class _PortdbProxy(portage.util.ObjectProxy):
 
        def _get_target(self):
                init_legacy_globals()
-               global db, portdb, root
-               if portdb is self:
+               global db, portdb, root, _portdb_initialized
+               if not _portdb_initialized:
                        portdb = db[root]["porttree"].dbapi
+                       _portdb_initialized = True
                return portdb
 
+class _MtimedbProxy(portage.util.ObjectProxy):
+       """
+       The mtimedb is independent from the portdb and other globals.
+       """
+
+       def __init__(self, name):
+               portage.util.ObjectProxy.__init__(self)
+               object.__setattr__(self, '_name', name)
+
+       def _get_target(self):
+               global mtimedb, mtimedbfile, _mtimedb_initialized
+               if not _mtimedb_initialized:
+                       mtimedbfile = os.path.join("/",
+                               CACHE_PATH.lstrip(os.path.sep), "mtimedb")
+                       mtimedb = MtimeDB(mtimedbfile)
+                       _mtimedb_initialized = True
+               name = object.__getattribute__(self, '_name')
+               return globals()[name]
+
 # Initialization of legacy globals.  No functions/classes below this point
 # please!  When the above functions and classes become independent of the
 # below global variables, it will be possible to make the below code
@@ -6943,8 +6963,6 @@ class _PortdbProxy(portage.util.ObjectProxy):
 # code that is aware of this flag to import portage without the unnecessary
 # overhead (and other issues!) of initializing the legacy globals.
 
-_globals_initialized = False
-
 def init_legacy_globals():
        global _globals_initialized
        if _globals_initialized:
@@ -6976,8 +6994,6 @@ def init_legacy_globals():
 
        root = settings["ROOT"]
 
-       mtimedbfile = os.path.join("/", CACHE_PATH.lstrip(os.path.sep), "mtimedb")
-       mtimedb = MtimeDB(mtimedbfile)
 
        # ========================================================================
        # COMPATIBILITY
@@ -7007,9 +7023,18 @@ def init_legacy_globals():
 # use within Portage.  External use of this variable is unsupported because
 # it is experimental and it's behavior is likely to change.
 if "PORTAGE_LEGACY_GLOBALS" not in os.environ:
+
+       _mtimedb_initialized = False
+       mtimedb     = _MtimedbProxy("mtimedb")
+       mtimedbfile = _MtimedbProxy("mtimedbfile")
+
+       _portdb_initialized  = False
        portdb = _PortdbProxy()
+
+       _globals_initialized = False
+
        for k in ("db", "settings", "root", "selinux_enabled",
-               "mtimedbfile", "mtimedb", "archlist", "features", "groups",
+               "archlist", "features", "groups",
                "pkglines", "thirdpartymirrors", "usedefaults", "profiledir",
                "flushmtimedb"):
                globals()[k] = _LegacyGlobalProxy(k)