def handle(self, **options): from django.conf import settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) self.stdout.write("-" * 79) for key in sorted(user_settings): display = False if key not in default_settings: display = True elif user_settings[key] != default_settings[key]: display = True elif options["all"]: display = True if display: value = user_settings[key] try: pformated = pprint.pformat(value) except Exception as err: # e.g.: https://github.com/andymccurdy/redis-py/issues/995 pformated = "<Error: %s>" % err self.stdout.write("%s = %s\n\n" % (key, pformated)) self.stdout.write("-" * 79)
def _detect_loader(): # pragma: no cover from django.conf import settings if settings.configured: return DjangoLoader try: # A settings module may be defined, but Django didn't attempt to # load it yet. As an alternative to calling the private _setup(), # we could also check whether DJANGO_SETTINGS_MODULE is set. settings._setup() except ImportError: if not callable(getattr(os, "fork", None)): # Platform doesn't support fork() # XXX On systems without fork, multiprocessing seems to be # launching the processes in some other way which does # not copy the memory of the parent process. This means # any configured env might be lost. This is a hack to make # it work on Windows. # A better way might be to use os.environ to set the currently # used configuration method so to propogate it to the "child" # processes. But this has to be experimented with. # [asksol/heyman] from django.core.management import setup_environ try: settings_mod = os.environ.get("DJANGO_SETTINGS_MODULE", "settings") project_settings = __import__(settings_mod, {}, {}, ['']) setup_environ(project_settings) return DjangoLoader except ImportError: pass else: return DjangoLoader return DefaultLoader
def handle(self, **options): from django.conf import settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) self.stdout.write("-"*79) for key in sorted(user_settings): display = False if key not in default_settings: display = True elif user_settings[key] != default_settings[key]: display = True elif options['all']: display = True if display: self.stdout.write( "%s = %s\n\n" % (key, pprint.pformat(user_settings[key])) ) self.stdout.write("-" * 79)
def initialize_django(settings_module: str) -> Tuple["Apps", "LazySettings"]: with temp_environ(): os.environ["DJANGO_SETTINGS_MODULE"] = settings_module # add current directory to sys.path sys.path.append(os.getcwd()) def noop_class_getitem(cls, key): return cls from django.db import models models.QuerySet.__class_getitem__ = classmethod(noop_class_getitem) # type: ignore models.Manager.__class_getitem__ = classmethod(noop_class_getitem) # type: ignore # Define mypy builtins, to not cause NameError during setting up Django. # TODO: temporary/unpatch builtins.reveal_type = lambda _: None builtins.reveal_locals = lambda: None from django.apps import apps from django.conf import settings apps.get_models.cache_clear() # type: ignore apps.get_swappable_settings_name.cache_clear() # type: ignore if not settings.configured: settings._setup() apps.populate(settings.INSTALLED_APPS) assert apps.apps_ready assert settings.configured return apps, settings
def handle_noargs(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) opts = Options() pformat = "%-25s = %s" puts('') for section in opts.sections: puts(colored.green("[%s]" % section)) for key, kaio_value in opts.items(section): keycolor = colored.magenta(key) if key in user_settings: keycolor = colored.blue(key) default_value = opts.options[key].default_value value = kaio_value or default_value if sys.version_info[0] < 3: value = unicode(value).encode('utf8') else: value = str(value) try: puts(pformat % (keycolor, value)) except Exception as e: raise e puts('')
def activate(self, directory, settings, update_pythonpath=True, import_settings=False): import os import sys os.environ['DJANGO_SETTINGS_MODULE'] = settings self.prev_sys_path = list(sys.path) self.prev_py_path = os.environ.get('PYTHONPATH', None) container = os.path.normpath(os.path.join(directory, os.pardir)) for path in (container, directory): if path not in self.prev_sys_path: sys.path.append(path) if update_pythonpath: py_path = os.environ.get('PYTHONPATH', None) os.environ['PYTHONPATH'] = \ os.pathsep.join((py_path, path)) if py_path else path if not import_settings: return import django from django.conf import settings if django.get_version() >= '1.7': django.setup() elif not settings.configured: settings._setup()
def handle_noargs(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) opts = Options() pformat = "%-25s = %s" puts('') for section in opts.sections: puts(colored.green("[%s]" % section)) for key, kaio_value in opts.items(section): keycolor = colored.magenta(key) if key in user_settings: keycolor = colored.blue(key) default_value = opts.options[key].default_value value = kaio_value or default_value if sys.version_info[0] < 3: value = unicode(value).encode('utf8') else: value = str(value) try: puts(pformat % (keycolor, value)) except Exception as e: raise e puts('')
def initialize_django(settings_module: str) -> Tuple['Apps', 'LazySettings']: with temp_environ(): os.environ['DJANGO_SETTINGS_MODULE'] = settings_module # add current directory to sys.path sys.path.append(os.getcwd()) def noop_class_getitem(cls, key): return cls from django.db import models models.QuerySet.__class_getitem__ = classmethod( noop_class_getitem) # type: ignore models.Manager.__class_getitem__ = classmethod( noop_class_getitem) # type: ignore from django.conf import settings from django.apps import apps apps.get_models.cache_clear() # type: ignore apps.get_swappable_settings_name.cache_clear() # type: ignore if not settings.configured: settings._setup() apps.populate(settings.INSTALLED_APPS) assert apps.apps_ready assert settings.configured return apps, settings
def handle_noargs(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) opts = Options() from clint.textui import puts, colored pformat = "%30s: %-30s %-30s %-30s" puts('') puts(pformat % (colored.white('Option'), colored.cyan('APP Value'), colored.cyan('INI Value'), colored.green('APP Default'))) puts('') for section in opts.sections: puts(pformat % (colored.green("[%s]" % section), '', '', '')) for key, kaio_value in opts.items(section): keycolor = colored.magenta(key) if key in user_settings: value = colored.green(user_settings[key]) keycolor = colored.blue(key) else: value = colored.green( opts.options[key].get_value_or_default()) default_value = opts.options[key].default_value kaio_value = kaio_value if kaio_value else repr(kaio_value) puts(pformat % (keycolor, clint_encode(value), colored.white(clint_encode(kaio_value)), clint_encode(default_value))) puts('') puts( colored.white( "No configurables directamente en INI (estáticos o compuestos por otros):" )) puts() not_configured = set(user_settings.keys()) - set(opts.keys()) # not_configured = not_configured - set([ # 'INSTALLED_APPS', # 'MIDDLEWARE_CLASSES', # 'CONTEXT_PROCESSORS', # ]) pformat = "%30s: %-50s" puts(pformat % (colored.white('Option'), colored.cyan('Value'))) for key in sorted(not_configured): if key not in default_settings: puts(pformat % (colored.blue(key), user_settings[key])) elif user_settings[key] != default_settings[key]: puts(pformat % ( colored.blue(key), colored.green(user_settings[key]) # colored.white(default_settings[key]) ))
def handle(self, **options): from django.conf import settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) self.stdout.write("-" * 79) for key in sorted(user_settings): display = False if key not in default_settings: display = True elif user_settings[key] != default_settings[key]: display = True elif options['all']: display = True if display: self.stdout.write("%s = %s\n\n" % (key, pprint.pformat(user_settings[key]))) self.stdout.write("-" * 79)
def get_django_settings(self): # Set the environment exactly how it should be for runserver. # Supervisor environment can hold the sparks settings, # while Django environment will hold the project settings. if hasattr(env, 'environment_vars'): for env_var in env.environment_vars: name, value = env_var.strip().split('=') os.environ[name] = value if hasattr(env, 'sparks_djsettings'): os.environ['SPARKS_DJANGO_SETTINGS'] = env.sparks_djsettings os.environ['DJANGO_SETTINGS_MODULE'] = \ '{0}.settings'.format(env.project) # Insert the $CWD in sys path, and pray for the user to have called # `fab` from where `manage.py` is. This is the way it should be done # but who knows… current_root = env.root if (hasattr(env, 'root') and is_local_environment()) else os.getcwd() sys.path.append(current_root) try: from django.conf import settings as django_settings # Avoid Django to (re-)configure our own logging; # the Fabric output becomes a mess without this. django_settings.__class__._configure_logging = lambda x: None django_settings._setup() except ImportError: LOGGER.warning(('Django settings could not be loaded for ' 'project "{0}" (which should be ' 'located in "{1}", with env. {2}{3}' ')').format( env.project, current_root, 'SPARKS_DJANGO_SETTINGS={0}'.format( env.sparks_djsettings) if hasattr(env, 'sparks_djsettings') else '', ' '.join(env.environment_vars) if hasattr(env, 'environment_vars') else '')) raise else: self.django_settings = django_settings._wrapped finally: sys.path.remove(current_root) del os.environ['DJANGO_SETTINGS_MODULE'] if hasattr(env, 'sparks_djsettings'): del os.environ['SPARKS_DJANGO_SETTINGS'] if hasattr(env, 'environment_vars'): for env_var in env.environment_vars: del os.environ[name]
def get_django_settings(self): # Set the environment exactly how it should be for runserver. # Supervisor environment can hold the sparks settings, # while Django environment will hold the project settings. if hasattr(env, 'environment_vars'): for env_var in env.environment_vars: name, value = env_var.strip().split('=') os.environ[name] = value if hasattr(env, 'sparks_djsettings'): os.environ['SPARKS_DJANGO_SETTINGS'] = env.sparks_djsettings os.environ['DJANGO_SETTINGS_MODULE'] = \ '{0}.settings'.format(env.project) # Insert the $CWD in sys path, and pray for the user to have called # `fab` from where `manage.py` is. This is the way it should be done # but who knows… current_root = env.root if ( hasattr(env, 'root') and is_local_environment()) else os.getcwd() sys.path.append(current_root) try: from django.conf import settings as django_settings # Avoid Django to (re-)configure our own logging; # the Fabric output becomes a mess without this. django_settings.__class__._configure_logging = lambda x: None django_settings._setup() except ImportError: LOGGER.warning( ('Django settings could not be loaded for ' 'project "{0}" (which should be ' 'located in "{1}", with env. {2}{3}' ')').format( env.project, current_root, 'SPARKS_DJANGO_SETTINGS={0}'.format(env.sparks_djsettings) if hasattr(env, 'sparks_djsettings') else '', ' '.join(env.environment_vars) if hasattr( env, 'environment_vars') else '')) raise else: self.django_settings = django_settings._wrapped finally: sys.path.remove(current_root) del os.environ['DJANGO_SETTINGS_MODULE'] if hasattr(env, 'sparks_djsettings'): del os.environ['SPARKS_DJANGO_SETTINGS'] if hasattr(env, 'environment_vars'): for env_var in env.environment_vars: del os.environ[name]
def setup_django_settings(test_settings): """Override the enviroment variable and call the _setup method of the settings object to reload them.""" os.environ['DJANGO_SETTINGS_MODULE'] = test_settings from django.conf import settings as django_settings # (re)setup django settings django_settings._setup() # reload settings reload_settings(django_settings)
def setup_django_settings(test_settings): """Override the enviroment variable and call the _setup method of the settings object to reload them.""" os.environ["DJANGO_SETTINGS_MODULE"] = test_settings from django.conf import settings as django_settings # (re)setup django settings django_settings._setup() # reload settings reload_settings(django_settings)
def setup(filename): clear_django() folder = os.path.dirname(filename) name = os.path.basename(filename).split('.')[0] fp, filen, desc = imp.find_module(name, [folder]) try: mod = imp.load_module(name, fp, filen, desc) finally: if fp: fp.close() setup_environ(mod) from django.conf import settings settings._setup()
def test_no_settings_module(self): msg = ( 'Requested setting%s, but settings are not configured. You ' 'must either define the environment variable DJANGO_SETTINGS_MODULE ' 'or call settings.configure() before accessing settings.') orig_settings = os.environ[ENVIRONMENT_VARIABLE] os.environ[ENVIRONMENT_VARIABLE] = '' try: with self.assertRaisesMessage(ImproperlyConfigured, msg % 's'): settings._setup() with self.assertRaisesMessage(ImproperlyConfigured, msg % ' TEST'): settings._setup('TEST') finally: os.environ[ENVIRONMENT_VARIABLE] = orig_settings
def handle(self, **options): from django.conf import settings, Settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default = options['default'] default_settings = module_to_dict(Settings(default) if default else global_settings) output_func = { 'hash': self.output_hash, 'unified': self.output_unified, }[options['output']] return '\n'.join(output_func(user_settings, default_settings, **options))
def handle(self, **options): from django.conf import settings, Settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default = options['default'] default_settings = module_to_dict(Settings(default) if default else global_settings) output_func = { 'hash': self.output_hash, 'unified': self.output_unified, }[options['output']] return '\n'.join(output_func(user_settings, default_settings, **options))
def test_no_settings_module(self): msg = ( 'Requested setting%s, but settings are not configured. You ' 'must either define the environment variable DJANGO_SETTINGS_MODULE ' 'or call settings.configure() before accessing settings.' ) orig_settings = os.environ[ENVIRONMENT_VARIABLE] os.environ[ENVIRONMENT_VARIABLE] = '' try: with self.assertRaisesMessage(ImproperlyConfigured, msg % 's'): settings._setup() with self.assertRaisesMessage(ImproperlyConfigured, msg % ' TEST'): settings._setup('TEST') finally: os.environ[ENVIRONMENT_VARIABLE] = orig_settings
def build_app_list(projects): """ Given a list of projects return a unique list of apps. """ apps = set() for project in projects: setup_project(project) settings._setup() for app in settings.INSTALLED_APPS: if app in EXTRA_APP_ALIASES: apps.update(EXTRA_APP_ALIASES[app]) apps.add(app) return list(apps)
def build_app_list(projects): """ Given a list of projects return a unique list of apps. """ apps = set() for project in projects: setup_project(project) settings._setup() for app in settings.INSTALLED_APPS: if app in EXTRA_APP_ALIASES: apps.update(EXTRA_APP_ALIASES[app]) apps.add(app) return list(apps)
def handle_noargs(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) output = [] for key in sorted(user_settings.keys()): if key not in default_settings: output.append("%s = %s ###" % (key, user_settings[key])) elif user_settings[key] != default_settings[key]: output.append("%s = %s" % (key, user_settings[key])) return '\n'.join(output)
def handle(self, **options): from django.conf import Settings, global_settings, settings # Because settings are imported lazily, we need to explicitly load them. if not settings.configured: settings._setup() user_settings = module_to_dict(settings._wrapped) default = options["default"] default_settings = module_to_dict( Settings(default) if default else global_settings) output_func = { "hash": self.output_hash, "unified": self.output_unified, }[options["output"]] return "\n".join( output_func(user_settings, default_settings, **options))
def handle_noargs(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) output = [] for key in sorted(user_settings.keys()): if key not in default_settings: output.append("%s = %s ###" % (key, user_settings[key])) elif user_settings[key] != default_settings[key]: output.append("%s = %s" % (key, user_settings[key])) return '\n'.join(output)
def test_django(): """Test in a real django environment""" # Use django to read and process the settings file from django.conf import settings, global_settings os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'test.settings_django') settings._setup() # Get the ones we're interested in all_settings = settings_dict(settings._wrapped) default_settings = settings_dict(global_settings) user_settings = {k: v for k, v in all_settings.items() if not(k in default_settings)} dump_settings('test_django', user_settings) assert user_settings['JSLIB_URL'] == 'http://example.cdn/jslib/2.5.3/jslib.js' assert user_settings['CHARACTER'] == 'Batman' assert user_settings['HAPPY_KID'] == 'Zombo'
def showsettings(request): settings._setup() def module_to_dict(module, omittable=lambda k: k.startswith('_')): """Converts a module namespace to a Python dictionary.""" return {k: repr(v) for k, v in module.__dict__.items() if not omittable(k)} user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) output = [] for key in sorted(user_settings): if key not in default_settings: output.append("%s = %s ###" % (key, user_settings[key])) elif user_settings[key] != default_settings[key]: output.append("%s = %s" % (key, user_settings[key])) else: output.append("### %s = %s" % (key, user_settings[key])) logger.debug('\n'.join(output)) html = "<html><body>Check the log</body></html>" return HttpResponse(html)
def test_django(): """Test in a real django environment""" # Use django to read and process the settings file from django.conf import settings, global_settings os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'test.settings_django') settings._setup() # Get the ones we're interested in all_settings = settings_dict(settings._wrapped) default_settings = settings_dict(global_settings) user_settings = { k: v for k, v in all_settings.items() if not (k in default_settings) } dump_settings('test_django', user_settings) assert user_settings[ 'JSLIB_URL'] == 'http://example.cdn/jslib/2.5.3/jslib.js' assert user_settings['CHARACTER'] == 'Batman' assert user_settings['HAPPY_KID'] == 'Zombo'
def handle_noargs(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings, global_settings from djset import secret, config # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) output = [] nb = False note_key = [] all_settings = options.get('all') for key in sorted(user_settings.keys()): line = [] value = user_settings[key] if key not in default_settings: line.append("%s = %s ### " % (key, value)) elif all_settings or (user_settings[key] != default_settings[key]): line.append("%s = %s " % (key, value)) # Annotate the values with the djset source if key in secret.kns: line.append("# (%s) " % secret.kns.get(key)) if key in config.kns: line.append("# (%s) " % config.kns.get(key)) if key in secret.kns and key in config.kns: line.append('***') note_key.append(key) nb = True if line: output.append(''.join(line)) if nb: output.append( "*** Designates setting(s) '%s' set by both Djset config and secret. " \ "The actual source will depend on the order they were evaluated." % ', '.join(note_key) ) return '\n'.join(output)
def handle_noargs(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) opts = Options() from clint.textui import puts, colored pformat = "%-25s = %s" puts('') for section in opts.sections: puts(colored.green("[%s]" % section)) for key, apconf_value in opts.items(section): keycolor = colored.magenta(key) if key in user_settings: #value = colored.green(user_settings[key]) keycolor = colored.blue(key) #else: #value = colored.green(opts.options[key].get_value_or_default()) default_value = opts.options[key].default_value #apconf_value = apconf_value if apconf_value else '-' value = apconf_value or default_value value = unicode(value).encode('utf8') try: puts(pformat % ( keycolor, value)) except Exception as e: raise e puts('')
def showsettings(request): settings._setup() def module_to_dict(module, omittable=lambda k: k.startswith('_')): """Converts a module namespace to a Python dictionary.""" return { k: repr(v) for k, v in module.__dict__.items() if not omittable(k) } user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) output = [] for key in sorted(user_settings): if key not in default_settings: output.append("%s = %s ###" % (key, user_settings[key])) elif user_settings[key] != default_settings[key]: output.append("%s = %s" % (key, user_settings[key])) else: output.append("### %s = %s" % (key, user_settings[key])) logger.debug('\n'.join(output)) html = "<html><body>Check the log</body></html>" return HttpResponse(html)
from django.utils.functional import empty from django.utils.timezone import is_aware, make_naive from website.misc.factories import UserFactory logging.debug("settings._wrapped: %s", settings._wrapped) # To avoid any configuration hiccups and all that boilerplate test runner settings # just to get Django not complain about it being not configured we'll do it here # now SimpleTestCase should work without any database setup overhead # noinspection PyProtectedMember if settings._wrapped is empty: os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings") # noinspection PyProtectedMember settings._setup() if not apps.ready: django.setup() for path in sys.path: logging.debug("sys.path: %s", path) from datetime import date, datetime # noqa F402 isort:skip from django.test import Client, TestCase # noqa F402 isort:skip from django.test.runner import DiscoverRunner # noqa F402 isort:skip # from test_plus import TestCase from django_powerbank.testing.base import AssertionsMx # noqa F402 isort:skip
from django.core.management.base import BaseCommand
# DEALINGS IN THE SOFTWARE. __author__ = 'William T. Katz' import config import os import sys # Force sys.path to have our own directory first, so we can import from it. sys.path.insert(0, config.APP_ROOT_DIR) sys.path.insert(1, os.path.join(config.APP_ROOT_DIR, 'utils/external')) os.environ['DJANGO_SETTINGS_MODULE'] = 'config' from django.conf import settings settings._setup() #needed to initialize template tags import logging #import wsgiref.handlers from google.appengine.ext import webapp from google.appengine.api import users from handlers.bloog import blog, contact, cache_stats, timings, imagestore # Configure logging for debug if in dev environment if config.DEBUG: logging.getLogger().setLevel(logging.DEBUG) # Log a message each time this module get loaded. logging.info('Loading %s, app version = %s', __name__, os.getenv('CURRENT_VERSION_ID'))
def setup(): settings._setup()
def tearDown(self): """ Must reset after every test """ from django.conf import settings settings._setup() # pylint: disable=protected-access
import sys, os, traceback from django.conf import settings as django_settings import tornado.httpserver import tornado.ioloop from tornado.web import RequestHandler # load settings os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' django_settings._setup() # import to path one directory up path = os.path.abspath(__file__) path = path[0:path.rfind("/")] sys.path.append(path[0:path.rfind("/")]) # create the app from cab import settings from cab.urls import urls app_settings = { "static_path": os.path.join(os.path.dirname(__file__), "public"), "cookie_secret": "61oETzKXQAGaYdkA5gEmGEJjFugh7e5np2XdTP1o=/0/", "login_url": "/login", "xsrf_cookies": True, } application = tornado.web.Application(urls, **app_settings) runserver = True if len(sys.argv) > 1: runserver = False arg = sys.argv[1] if arg == "cron":
def test_incorrect_timezone(self): with self.assertRaisesMessage(ValueError, 'Incorrect timezone setting: test'): settings._setup()
def _perform_reset(): """ Defers to the original django.conf.settings to a new initialization """ base_settings._setup() # pylint: disable=protected-access LOG.debug("Reset on the settings object for PID: %s", os.getpid())
import os from django.conf import settings os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings' settings._setup()
# DEALINGS IN THE SOFTWARE. __author__ = 'William T. Katz' import config import os import sys # Force sys.path to have our own directory first, so we can import from it. sys.path.insert(0, config.APP_ROOT_DIR) sys.path.insert(1, os.path.join(config.APP_ROOT_DIR, 'utils/external')) os.environ['DJANGO_SETTINGS_MODULE'] = 'config' from django.conf import settings settings._setup() #needed to initialize template tags import logging #import wsgiref.handlers from google.appengine.ext import webapp from google.appengine.api import users from handlers.bloog import blog, contact, cache_stats, timings, imagestore # Configure logging for debug if in dev environment if config.DEBUG: logging.getLogger().setLevel(logging.DEBUG) # Log a message each time this module get loaded. logging.info('Loading %s, app version = %s', __name__, os.getenv('CURRENT_VERSION_ID'))
def tearDown(self): """ Must reset after every test """ settings._setup() # pylint: disable=protected-access
def handle_noargs(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) #import ipdb;ipdb.set_trace() opts = Options() from clint.textui import puts, colored pformat = "%30s: %-30s %-30s %-30s" puts('') puts(pformat % ( colored.white('Option'), colored.cyan('APP Value'), colored.cyan('INI Value'), colored.green('APP Default'))) puts('') for section in opts.sections: puts(pformat % (colored.green("[%s]" % section), '', '', '')) for key, apconf_value in opts.items(section): keycolor = colored.magenta(key) if key in user_settings: value = colored.green(user_settings[key]) keycolor = colored.blue(key) else: value = colored.green(opts.options[key].get_value_or_default()) default_value = opts.options[key].default_value apconf_value = apconf_value if apconf_value else repr(apconf_value) puts(pformat % ( keycolor, clint_encode(value), colored.white(clint_encode(apconf_value)), clint_encode(default_value))) puts('') puts(colored.white("No configurables directamente en INI (estáticos o compuestos por otros):")) puts() not_configured = set(user_settings.keys()) - set(opts.keys()) #not_configured = not_configured - set([ #'INSTALLED_APPS', #'MIDDLEWARE_CLASSES', #'CONTEXT_PROCESSORS', #]) pformat = "%30s: %-50s" puts(pformat % ( colored.white('Option'), colored.cyan('Value'))) for key in sorted(not_configured): if key not in default_settings: puts(pformat % (colored.blue(key), user_settings[key])) #'###')) elif user_settings[key] != default_settings[key]: puts(pformat % ( colored.blue(key), colored.green(user_settings[key])))
def test_incorrect_timezone(self): with self.assertRaisesMessage(ValueError, 'Incorrect timezone setting: test'): settings._setup()
def _perform_reset(): """Defers to the original django.conf.settings to a new initialization.""" base_settings._setup() # pylint: disable=protected-access importlib.reload(conf)