Skip to content

Instantly share code, notes, and snippets.

@justinabrahms
Created October 23, 2009 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save justinabrahms/217198 to your computer and use it in GitHub Desktop.
Save justinabrahms/217198 to your computer and use it in GitHub Desktop.
"""
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.
"""
HOSTMAP = {
'local_dev': [
'jlilly-mb.mydomain.com',
],
'qa':[
'nyicolo-dev69',
],
'staging':[
'stg-admin1.mydomain.com',
'stg-web1.mydomain.com',
'stg-web2.mydomain.com',
],
'procudtion':[
],
}
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)
update_current_settings('settings.base_settings')
for x in to_load:
try:
update_current_settings('settings.settings_%s' % x)
except ImportError:
print "Error importing %s" % x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment