__init__.py
1.11 KB
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
import inspect
import pkgutil
import os
from pprint import pformat
import sys
ordering = ('env', 'local_env', 'paths')
modules = [x[1] for x in pkgutil.walk_packages(__path__)]
modules.sort(key=lambda x: x in ordering and ordering.index(x) + 1 or sys.maxint)
print 'Loading {{ project_name }}.settings submodules: %s' % (", ".join(modules))
for module_name in modules:
module = __import__(module_name, globals(), locals(), [])
for var_name, val in inspect.getmembers(module):
if var_name.isupper():
locals().update({var_name: val})
try:
# noinspection PyUnresolvedReferences
from ..settings_local import *
except ImportError:
pass
settingsraw = []
for s in locals().copy():
if s.isupper():
try:
settingsraw.append("%s = %s\n" % (s, pformat(locals()[s], indent=0, width=100000)))
except:
pass
settingsfile = os.path.dirname(__file__) + '/../settings_compiled.py'
if not os.path.isfile(settingsfile) or open(settingsfile).readlines() != settingsraw:
print 'Updating compiled settings file ...'
file(settingsfile, 'wb').writelines(settingsraw)