Skip to content

Instantly share code, notes, and snippets.

@fidiego
Last active October 26, 2015 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fidiego/d5233446a73abd5919d0 to your computer and use it in GitHub Desktop.
Save fidiego/d5233446a73abd5919d0 to your computer and use it in GitHub Desktop.
'''
platform_data_api/settings/__init__.py
--------------------------------------
Reads the environment and configures all the things
'''
from load_conf import config
ENV = ENVIRONMENT = config['env']
if ENV == 'production':
from settings.prod import *
elif ENV == 'stage':
from settings.stage import *
else:
from settings.dev import *
'''
${project}/settings/load_conf.py
---------------------------------------
'''
import os
import json
current_directory = os.path.dirname(os.path.realpath(__file__))
possible_file_paths = [
os.path.join(current_directory, 'local_settings.json'),
'/buzzfeed/local/conf/platform_data_api_conf.json'
]
config = None
for file_path in possible_file_paths:
if not os.path.isfile(file_path):
continue
with open(file_path, 'r') as f:
file_data = f.read()
config = json.loads(file_data)
break
if not config:
raise SystemError('Invalid or missing config file')
is_empty = lambda s: None if s == '' else s
config = {k: is_empty(config[k]) for k in config}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment