nowells (owner)

Revisions

gist: 217737 Download_button fork
public
Public Clone URL: git://gist.github.com/217737.git
Embed All Files: show embed
django_settings_file.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
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