summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-04-29 10:16:20 +0000
committerZac Medico <zmedico@gentoo.org>2006-04-29 10:16:20 +0000
commitff95742f3a582abe07253eb027be97f80003fed0 (patch)
treeff086e56591898412d9bebe036a119b8d9d81ac3
parentPass mtimes through doebuild(), into dblink.merge(), and finally to env_updat... (diff)
downloadportage-ff95742f3a582abe07253eb027be97f80003fed0.tar.gz
portage-ff95742f3a582abe07253eb027be97f80003fed0.tar.bz2
portage-ff95742f3a582abe07253eb027be97f80003fed0.zip
Move the legacy global initializations into a function and allow them to be disabled via an experimental PORTAGE_LEGACY_GLOBALS environment variable.
svn path=/main/trunk/; revision=3271
-rw-r--r--pym/portage.py138
1 files changed, 73 insertions, 65 deletions
diff --git a/pym/portage.py b/pym/portage.py
index 442b728ae..e33be078a 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -6825,77 +6825,85 @@ def do_vartree(mysettings, trees=None):
# code that is aware of this flag to import portage without the unnecessary
# overhead (and other issues!) of initializing the legacy globals.
-db={}
+def init_legacy_globals():
+ global db, settings, root, portdb, selinux_enabled, mtimedbfile, mtimedb, \
+ archlist, features, groups, pkglines, thirdpartymirrors, usedefaults, \
+ profiledir, flushmtimedb
-# We're going to lock the global config to prevent changes, but we need
-# to ensure the global settings are right.
-try:
- settings = config(config_profile_path=PROFILE_PATH,
- config_incrementals=portage_const.INCREMENTALS)
-except portage_exception.DirectoryNotFound, e:
- writemsg("!!! Directory Not Found: %s\n" % str(e))
- sys.exit(1)
-
-root = settings["ROOT"]
-
-do_vartree(settings, trees=db)
-settings.reset() # XXX: Regenerate use after we get a vartree -- GLOBAL
+ try:
+ settings = config(config_profile_path=PROFILE_PATH,
+ config_incrementals=portage_const.INCREMENTALS)
+ except portage_exception.DirectoryNotFound, e:
+ writemsg("!!! Directory Not Found: %s\n" % str(e))
+ sys.exit(1)
-# XXX: Might cause problems with root="/" assumptions
-portdb=portdbapi(settings["PORTDIR"])
+ settings.reset()
+ settings.lock()
+ settings.validate()
-settings.lock()
-settings.validate()
+ root = settings["ROOT"]
+ db={}
+ do_vartree(settings, trees=db)
+ portdb = portdbapi(settings["PORTDIR"], mysettings=config(clone=settings))
-if 'selinux' in settings["USE"].split(" "):
- try:
- import selinux
- if hasattr(selinux, "enabled"):
- selinux_enabled = selinux.enabled
- else:
- selinux_enabled = 1
- except OSError, e:
- writemsg(red("!!! SELinux not loaded: ")+str(e)+"\n")
- selinux_enabled=0
- except ImportError:
- writemsg(red("!!! SELinux module not found.")+" Please verify that it was installed.\n")
+ if 'selinux' in settings["USE"].split(" "):
+ try:
+ import selinux
+ if hasattr(selinux, "enabled"):
+ selinux_enabled = selinux.enabled
+ else:
+ selinux_enabled = 1
+ except OSError, e:
+ writemsg(red("!!! SELinux not loaded: ")+str(e)+"\n")
+ selinux_enabled=0
+ except ImportError:
+ writemsg(red("!!! SELinux module not found.")+" Please verify that it was installed.\n")
+ selinux_enabled=0
+ if selinux_enabled == 0:
+ try:
+ del sys.modules["selinux"]
+ except KeyError:
+ pass
+ else:
selinux_enabled=0
- if selinux_enabled == 0:
- try:
- del sys.modules["selinux"]
- except KeyError:
- pass
-else:
- selinux_enabled=0
-
-mtimedbfile = os.path.join(root, CACHE_PATH.lstrip(os.path.sep), "mtimedb")
-try:
- f = open(mtimedbfile)
- mtimedb = load_mtimedb(f)
- f.close()
- del f
-except (IOError, OSError):
- mtimedb = {"updates":{}, "ldpath":{}, "version":"", "starttime":0}
-# ============================================================================
-# COMPATIBILITY
-# These attributes should not be used within Portage under any circumstances.
-# ============================================================================
-archlist = settings.archlist()
-features = settings.features
-groups = settings["ACCEPT_KEYWORDS"].split()
-pkglines = settings.packages
-thirdpartymirrors = settings.thirdpartymirrors()
-usedefaults = settings.use_defs
-profiledir = None
-if os.path.isdir(PROFILE_PATH):
- profiledir = PROFILE_PATH
-def flushmtimedb(record):
- writemsg("portage.flushmtimedb() is DEPRECATED\n")
-# ============================================================================
-# COMPATIBILITY
-# These attributes should not be used within Portage under any circumstances.
-# ============================================================================
+ mtimedbfile = os.path.join(root, CACHE_PATH.lstrip(os.path.sep), "mtimedb")
+ try:
+ f = open(mtimedbfile)
+ mtimedb = load_mtimedb(f)
+ f.close()
+ del f
+ except (IOError, OSError):
+ mtimedb = {"updates":{}, "ldpath":{}, "version":"", "starttime":0}
+
+ # ========================================================================
+ # COMPATIBILITY
+ # These attributes should not be used
+ # within Portage under any circumstances.
+ # ========================================================================
+ archlist = settings.archlist()
+ features = settings.features
+ groups = settings["ACCEPT_KEYWORDS"].split()
+ pkglines = settings.packages
+ thirdpartymirrors = settings.thirdpartymirrors()
+ usedefaults = settings.use_defs
+ profiledir = None
+ if os.path.isdir(PROFILE_PATH):
+ profiledir = PROFILE_PATH
+ def flushmtimedb(record):
+ writemsg("portage.flushmtimedb() is DEPRECATED\n")
+ # ========================================================================
+ # COMPATIBILITY
+ # These attributes should not be used
+ # 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:
+ init_legacy_globals()
# Clear the cache
dircache={}