-
-
Save girasquid/252610 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
""" | |
The HOSTMAP variable is a dictionary of lists. The keys represent | |
roles of a server, the values represent the hostnames of machines that | |
fill those roles. If you are reading this, you likely know what you're | |
doing. If you don't know what you're doing, you probably want to put | |
your hostname into local_dev. Ensure it has a comma at the end, and | |
the hostname is a string. | |
You can get your hostname by typing `hostname` into a terminal. | |
This file will import *two* settings files, in addition to base_settings.py. First, | |
the key(settings_local_dev.py) - and then, the settings file for your machine specifically: | |
(settings_lifttop.py) | |
""" | |
HOSTMAP = { | |
'local_dev': [ | |
'Lifttop.local', | |
], | |
'production':[ | |
], | |
} | |
import socket | |
from django.utils import importlib | |
def update_current_settings(file_name): | |
""" | |
Given a filename, this function will insert all variables and | |
functions in ALL_CAPS into the global scope. | |
""" | |
new_settings = importlib.import_module(file_name) | |
for k, v in new_settings.__dict__.items(): | |
if k.upper() == k: | |
globals().update({k:v}) | |
current_hostname = socket.gethostname() | |
to_load = [] | |
for k, v in HOSTMAP.items(): | |
if current_hostname in v: | |
to_load.append(k) | |
to_load.append(current_hostname.split('.')[0]) # so that we import foo.settings, not foo.local.settings | |
update_current_settings('settings.base_settings') | |
for x in to_load: | |
try: | |
update_current_settings('settings.settings_%s' % x.lower()) | |
except ImportError, e: | |
print "Error importing %s:%s" % (x, e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment