Skip to content

Instantly share code, notes, and snippets.

@james-m
Created June 25, 2013 23:16
Show Gist options
  • Save james-m/5863343 to your computer and use it in GitHub Desktop.
Save james-m/5863343 to your computer and use it in GitHub Desktop.
import os
import sys
import context
def get_env_name():
env = None #'dev' # the default
env = os.environ.get('ENV_NAME', env)
if env is None:
raise Exception("ENV_NAME=None")
env = env.lower()
return env
def get_env_config(pre=False):
return 'conf.%(env)s%(pre_env)s' % {
'env': get_env_name(),
'pre_env': '_pre' if pre else ""}
def get_context():
return context.ctx()
CONF_DIR = os.path.split(os.path.abspath(__file__))[0]
MODULES = [
# module name, required?
('conf.version', False),
('conf.local_pre', False),
(get_env_config(pre=True), False),
('conf.all', True),
(get_env_config(), True),
('conf.local', False),
]
LOADED = False
def load(_reload=False):
global LOADED
if LOADED and not _reload:
return None
ctx = get_context()
ctx.clear()
for name, opt in MODULES:
try:
if name in sys.modules:
reload(sys.modules[name])
else:
__import__(name)
except ImportError, e:
if opt:
raise
LOADED = True
load()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment