From b88ca698dd4dc4eb486b08bdb10be9123ef01e8e Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 30 Nov 2014 12:49:26 -0600 Subject: An environment variable to transition towards removing global variables --- mediagoblin/app.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'mediagoblin/app.py') diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 8b231163..e5442010 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -42,6 +42,8 @@ from mediagoblin.tools.pluginapi import PluginManager, hook_transform from mediagoblin.tools.crypto import setup_crypto from mediagoblin.auth.tools import check_auth_enabled, no_auth_logout +from mediagoblin.tools.transition import DISABLE_GLOBALS + _log = logging.getLogger(__name__) @@ -150,9 +152,14 @@ class MediaGoblinApp(object): # certain properties need to be accessed globally eg from # validators, etc, which might not access to the request # object. + # + # Note, we are trying to transition this out; + # run with environment variable DISABLE_GLOBALS=true + # to work on it ####################################################### - setup_globals(app=self) + if not DISABLE_GLOBALS: + setup_globals(app=self) # Workbench *currently* only used by celery, so this only # matters in always eager mode :) @@ -174,12 +181,7 @@ class MediaGoblinApp(object): # -------------- # Is a context provided? - if ctx is not None: - # Do special things if this is a request - if isinstance(ctx, Request): - ctx = self._request_only_gen_context(ctx) - - else: + if ctx is None: ctx = Context() # Attach utilities @@ -192,6 +194,11 @@ class MediaGoblinApp(object): ctx.db = self.db ctx.staticdirect = self.staticdirector + # Do special things if this is a request + # -------------------------------------- + if isinstance(ctx, Request): + ctx = self._request_only_gen_context(ctx) + return ctx def _request_only_gen_context(self, request): -- cgit v1.2.3