From: Zac Medico Date: Mon, 11 Feb 2013 09:38:58 +0000 (-0800) Subject: ebuild: add _reset_legacy_globals for reload X-Git-Tag: v2.2.0_alpha162~9 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b5e88117bf4ed0aec3ab537f8f280a15b050e40c;p=portage.git ebuild: add _reset_legacy_globals for reload 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). --- diff --git a/bin/ebuild b/bin/ebuild index 44b3c99d0..1ce4c9c80 100755 --- a/bin/ebuild +++ b/bin/ebuild @@ -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: diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index a8b692c1d..bc14bae38 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -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(): """