ebuild: add _reset_legacy_globals for reload
authorZac Medico <zmedico@gentoo.org>
Mon, 11 Feb 2013 09:38:58 +0000 (01:38 -0800)
committerZac Medico <zmedico@gentoo.org>
Mon, 11 Feb 2013 09:38:58 +0000 (01:38 -0800)
This avoids weird issues that are triggered when the module is
reloaded (like having classes redefined while instances from the old
classes are still around, triggering TypeError confusion).

bin/ebuild
pym/portage/__init__.py

index 44b3c99d0731937dd19b44b1392d8428bcb12364..1ce4c9c80e4a233545d848f5de952c7386052cf7 100755 (executable)
@@ -35,7 +35,6 @@ else:
 
 signal.signal(debug_signum, debug_signal)
 
-import imp
 import io
 import optparse
 import os
@@ -157,7 +156,7 @@ if ebuild_portdir != vdb_path and \
                        encoding=_encodings['content'], errors='strict')
 
        print("Appending %s to PORTDIR_OVERLAY..." % ebuild_portdir)
-       imp.reload(portage)
+       portage._reset_legacy_globals()
 
 myrepo = None
 if ebuild_portdir != vdb_path:
index a8b692c1d47baec63b4a0fbbef82d48ef387e13c..bc14bae381fb6909033e957f1fd8f0556aaca25b 100644 (file)
@@ -657,10 +657,17 @@ if VERSION == 'HEAD':
                        return VERSION
        VERSION = _LazyVersion()
 
-if "_legacy_globals_constructed" in globals():
-       # The module has been reloaded, so perform any relevant cleanup
-       # and prevent memory leaks.
-       if "db" in _legacy_globals_constructed:
+_legacy_global_var_names = ("archlist", "db", "features",
+       "groups", "mtimedb", "mtimedbfile", "pkglines",
+       "portdb", "profiledir", "root", "selinux_enabled",
+       "settings", "thirdpartymirrors")
+
+def _reset_legacy_globals():
+
+       global _legacy_globals_constructed
+
+       if "_legacy_globals_constructed" in globals() and \
+               "db" in _legacy_globals_constructed:
                try:
                        db
                except NameError:
@@ -684,7 +691,10 @@ if "_legacy_globals_constructed" in globals():
                                                portdbapi.portdbapi_instances.remove(_x)
                                        except ValueError:
                                                pass
-                               del _x
+
+       _legacy_globals_constructed = set()
+       for k in _legacy_global_var_names:
+               globals()[k] = _LegacyGlobalProxy(k)
 
 class _LegacyGlobalProxy(proxy.objectproxy.ObjectProxy):
 
@@ -699,16 +709,7 @@ class _LegacyGlobalProxy(proxy.objectproxy.ObjectProxy):
                from portage._legacy_globals import _get_legacy_global
                return _get_legacy_global(name)
 
-_legacy_global_var_names = ("archlist", "db", "features",
-       "groups", "mtimedb", "mtimedbfile", "pkglines",
-       "portdb", "profiledir", "root", "selinux_enabled",
-       "settings", "thirdpartymirrors")
-
-for k in _legacy_global_var_names:
-       globals()[k] = _LegacyGlobalProxy(k)
-del k
-
-_legacy_globals_constructed = set()
+_reset_legacy_globals()
 
 def _disable_legacy_globals():
        """