Last active
October 26, 2015 19:37
-
-
Save fidiego/d5233446a73abd5919d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
${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