When portage upgrades or downgrades itself, preload lazily referenced portage
authorZac Medico <zmedico@gentoo.org>
Tue, 9 Mar 2010 02:42:40 +0000 (02:42 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 9 Mar 2010 02:42:40 +0000 (02:42 -0000)
submodules into memory so that imports won't fail later. (trunk r15778)

svn path=/main/branches/2.1.7/; revision=15782

pym/portage/dbapi/vartree.py
pym/portage/proxy/lazyimport.py

index 2f09ecaa29156bf07940e10d0e914c611a2103a8..80b564fc93da15f966cb499a862be2d65d4c6ce8 100644 (file)
@@ -3181,6 +3181,9 @@ class dblink(object):
                if self.myroot == "/" and \
                        match_from_list(PORTAGE_PACKAGE_ATOM, [self.mycpv]) and \
                        not self.vartree.dbapi.cpv_exists(self.mycpv):
+                       # Load lazily referenced portage submodules into memory,
+                       # so imports won't fail during portage upgrade/downgrade.
+                       portage.proxy.lazyimport._preload_portage_submodules()
                        settings = self.settings
                        base_path_orig = os.path.dirname(settings["PORTAGE_BIN_PATH"])
                        from tempfile import mkdtemp
index c62f9078895e24c599e8f851ae828436f877ea85..84b2c730b0f25831c9232bfb0a6156302c68d0a2 100644 (file)
@@ -20,6 +20,24 @@ if sys.hexversion >= 0x3000000:
 _module_proxies = {}
 _module_proxies_lock = threading.RLock()
 
+def _preload_portage_submodules():
+       """
+       Load lazily referenced portage submodules into memory,
+       so imports won't fail during portage upgrade/downgrade.
+       Note that this recursively loads only the modules that
+       are lazily referenced by currently imported modules,
+       so some portage submodules may still remain unimported
+       after this function is called.
+       """
+       while True:
+               remaining = False
+               for name in list(_module_proxies):
+                       if name.startswith('portage.'):
+                               remaining = True
+                               _unregister_module_proxy(name)
+               if not remaining:
+                       break
+
 def _register_module_proxy(name, proxy):
        _module_proxies_lock.acquire()
        try: