Esempio n. 1
0
def dotenv_load(dotenv_file):
    """
    Loads a given .env file and merges it's contents with os.environ
    """
    try:
        dotenv = imp.load_source('dotenv', dotenv_file)
        dotenv = {attr: getattr(dotenv, attr) for attr in dir(dotenv) if not attr.startswith('_')}
        os.environ.update(dotenv)

        logger.debug('Loading .env vars from: %s' % dotenv_file)
    except IOError:
        pass
Esempio n. 2
0
def load_environment():
    configuration_arg_check = re.compile('^--configuration=(.+)$')
    configuration_args = filter(configuration_arg_check.match, sys.argv)

    if configuration_args:
        configuration = configuration_arg_check.match(configuration_args[0]).group(1)
        logger.debug('Configuration from arg: %s' % configuration)
        os.environ.setdefault('DJANGO_CONFIGURATION', configuration)
    else:
        logger.debug('Configuration from os.environ')
        os.environ.setdefault('DJANGO_CONFIGURATION', 'Local')

    dotenv_load('envs/%s.env' % os.environ['DJANGO_CONFIGURATION'])
Esempio n. 3
0
import os

import boilerplate.utils
from boilerplate import logger


boilerplate.utils.load_environment()
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')

from configurations.wsgi import get_wsgi_application
application = get_wsgi_application()

from django.conf import settings, global_settings


if not settings.DEBUG and settings.STATICFILES_STORAGE == global_settings.STATICFILES_STORAGE:
    # If we are using default staticfiles storage and not in DEBUG, serve through Cling WSGI middleware
    logger.debug('WSGI USING CLING')
    from dj_static import Cling
    application = Cling(application)
Esempio n. 4
0
import imp

import django.core.management

import boilerplate.utils
from boilerplate import logger


if __name__ != '__main__':
    raise Exception("manage.py should be run directly and not be imported")


# Load environment from configuration
boilerplate.utils.load_environment()
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')

try:
    # ugly - disgusting - crap
    imp.find_module(os.environ['DJANGO_SETTINGS_MODULE'])

    import configurations.management

    logger.debug('Executing from command line: %s' % sys.argv)
    configurations.management.execute_from_command_line(sys.argv)

except ImportError:
    os.environ['DJANGO_SETTINGS_MODULE'] = 'boilerplate.conf.empty_settings'
    django.core.management.execute_from_command_line(sys.argv)


Esempio n. 5
0
#!/usr/bin/env python
import os
import sys
import imp

import django.core.management

import boilerplate.utils
from boilerplate import logger

if __name__ != '__main__':
    raise Exception("manage.py should be run directly and not be imported")

# Load environment from configuration
boilerplate.utils.load_environment()
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')

try:
    # ugly - disgusting - crap
    imp.find_module(os.environ['DJANGO_SETTINGS_MODULE'])

    import configurations.management

    logger.debug('Executing from command line: %s' % sys.argv)
    configurations.management.execute_from_command_line(sys.argv)

except ImportError:
    os.environ['DJANGO_SETTINGS_MODULE'] = 'boilerplate.conf.empty_settings'
    django.core.management.execute_from_command_line(sys.argv)
Esempio n. 6
0
import os

import boilerplate.utils
from boilerplate import logger

boilerplate.utils.load_environment()
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')

from configurations.wsgi import get_wsgi_application
application = get_wsgi_application()

from django.conf import settings, global_settings

if not settings.DEBUG and settings.STATICFILES_STORAGE == global_settings.STATICFILES_STORAGE:
    # If we are using default staticfiles storage and not in DEBUG, serve through Cling WSGI middleware
    logger.debug('WSGI USING CLING')
    from dj_static import Cling
    application = Cling(application)