summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-03-09 02:36:00 +0000
committerZac Medico <zmedico@gentoo.org>2010-03-09 02:36:00 +0000
commitcd9e494b36b4ae554c88173309e9d4a054946e8c (patch)
tree1509211202e5ef1da17f22b192e32980b96231cd /pym
parente0dc5d7668bcbb09576733432f671129bfb41b28 (diff)
downloadportage-cd9e494b36b4ae554c88173309e9d4a054946e8c.tar.gz
portage-cd9e494b36b4ae554c88173309e9d4a054946e8c.tar.bz2
portage-cd9e494b36b4ae554c88173309e9d4a054946e8c.zip
When portage upgrades or downgrades itself, preload lazily referenced portage
submodules into memory so that imports won't fail later. svn path=/main/trunk/; revision=15778
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/dbapi/vartree.py3
-rw-r--r--pym/portage/proxy/lazyimport.py18
2 files changed, 21 insertions, 0 deletions
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 76a9034eb..4eee0cf05 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -4343,6 +4343,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
diff --git a/pym/portage/proxy/lazyimport.py b/pym/portage/proxy/lazyimport.py
index c62f90788..84b2c730b 100644
--- a/pym/portage/proxy/lazyimport.py
+++ b/pym/portage/proxy/lazyimport.py
@@ -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: