From 1bb31021102532794b844dc6d288867ae3a421de Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 3 Jul 2008 09:05:38 +0000 Subject: Add a portage._disable_legacy_globals() function. This deletes the ObjectProxy instances that are used for lazy initialization of legacy global variables. The purpose of deleting them is to prevent new code from referencing these deprecated variables. This allows the removal of the PORTAGE_LEGACY_GLOBALS variable which used to serve the same purpose. svn path=/main/trunk/; revision=10909 --- pym/_emerge/__init__.py | 3 +-- pym/portage/__init__.py | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'pym') diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index 78e70de71..8c30b4f01 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -31,14 +31,13 @@ import gc import os, stat import platform -os.environ["PORTAGE_LEGACY_GLOBALS"] = "false" try: import portage except ImportError: from os import path as osp sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym")) import portage -del os.environ["PORTAGE_LEGACY_GLOBALS"] +portage._disable_legacy_globals() from portage import digraph, portdbapi from portage.const import NEWS_LIB_PATH, CACHE_PATH, PRIVATE_PATH, USER_CONFIG_PATH, GLOBAL_CONFIG_PATH diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 16760c8d4..9859e0f5e 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -7009,6 +7009,22 @@ class _MtimedbProxy(portage.util.ObjectProxy): name = object.__getattribute__(self, '_name') return globals()[name] +_legacy_global_var_names = ("archlist", "db", "features", + "groups", "mtimedb", "mtimedbfile", "pkglines", + "portdb", "profiledir", "root", "selinux_enabled", + "settings", "thirdpartymirrors", "usedefaults") + +def _disable_legacy_globals(): + """ + This deletes the ObjectProxy instances that are used + for lazy initialization of legacy global variables. + The purpose of deleting them is to prevent new code + from referencing these deprecated variables. + """ + global _legacy_global_var_names + for k in _legacy_global_var_names: + globals().pop(k, None) + # 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 @@ -7072,11 +7088,7 @@ def init_legacy_globals(): # within Portage under any circumstances. # ======================================================================== -# WARNING! -# The PORTAGE_LEGACY_GLOBALS environment variable is reserved for internal -# 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: +if True: _mtimedb_initialized = False mtimedb = _MtimedbProxy("mtimedb") -- cgit v1.2.3-1-g7c22