Revision 32401481 snf-common/synnefo/settings/__init__.py
b/snf-common/synnefo/settings/__init__.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
import os |
35 |
import sys |
|
36 |
|
|
37 |
from synnefo.util.entry_points import extend_settings |
|
35 |
from sys import modules, stderr |
|
36 |
_module = modules[__name__] |
|
38 | 37 |
|
39 | 38 |
# set synnefo package __file__ to fix django related bug |
40 | 39 |
import synnefo |
41 | 40 |
synnefo.__file__ = os.path.join(synnefo.__path__[0], '__init__.py') |
42 | 41 |
|
43 |
# import default settings |
|
44 |
from synnefo.settings.default import * |
|
45 |
from .setup import Example, Default |
|
42 |
from .setup import Setting |
|
43 |
synnefo_settings = {} |
|
44 |
# insert global default synnefo settings |
|
45 |
from .default import * |
|
46 |
for name in dir(_module): |
|
47 |
if not Setting.is_valid_setting_name(name): |
|
48 |
continue |
|
49 |
synnefo_settings[name] = getattr(_module, name) |
|
46 | 50 |
|
47 | 51 |
# autodetect default settings provided by synnefo applications |
48 |
extend_settings(__name__, 'synnefo') |
|
49 |
|
|
50 |
SYNNEFO_SETTINGS_SETUP_MODULES = ['synnefo.settings.setup.services'] |
|
52 |
from synnefo.util.entry_points import get_entry_points |
|
53 |
for e in get_entry_points('synnefo', 'default_settings'): |
|
54 |
m = e.load() |
|
55 |
print "loading", m |
|
56 |
for name in dir(m): |
|
57 |
if name.startswith('__'): |
|
58 |
continue |
|
59 |
synnefo_settings[name] = getattr(m, name) |
|
51 | 60 |
|
52 |
from .setup import preproc_settings
|
|
53 |
preproc_settings(sys.modules[__name__])
|
|
54 |
del preproc_settings
|
|
61 |
# set strict to True to require annotation of all settings
|
|
62 |
Setting.initialize_settings(synnefo_settings, strict=False)
|
|
63 |
_module.__dict__.update(Setting.Catalogs['defaults'])
|
|
55 | 64 |
|
56 | 65 |
# extend default settings with settings provided within *.conf user files |
57 | 66 |
# located in directory specified in the SYNNEFO_SETTINGS_DIR |
58 | 67 |
# environment variable |
68 |
import re |
|
69 |
system_conf_re = re.compile('^([0-9]\+-)?system.conf$') |
|
70 |
|
|
59 | 71 |
SYNNEFO_SETTINGS_DIR = os.environ.get('SYNNEFO_SETTINGS_DIR', "/etc/synnefo/") |
60 | 72 |
if os.path.exists(SYNNEFO_SETTINGS_DIR): |
61 | 73 |
try: |
... | ... | |
64 | 76 |
conffiles = [f for f in entries if os.path.isfile(f) and |
65 | 77 |
f.endswith(".conf")] |
66 | 78 |
except Exception as e: |
67 |
print >> sys.stderr, "Failed to list *.conf files under %s" % \
|
|
79 |
print >> stderr, "Failed to list *.conf files under %s" % \ |
|
68 | 80 |
SYNNEFO_SETTINGS_DIR |
69 | 81 |
raise SystemExit(1) |
70 | 82 |
conffiles.sort() |
71 | 83 |
for f in conffiles: |
84 |
if system_conf_re.match(f): |
|
85 |
allow_known = False |
|
86 |
allow_unknown = True |
|
87 |
else: |
|
88 |
allow_known = True |
|
89 |
allow_unknown = False |
|
90 |
|
|
91 |
# FIXME: Hack until all settings have been annotated properly |
|
92 |
allow_unknown = True |
|
93 |
allow_override = True |
|
94 |
|
|
72 | 95 |
try: |
73 |
execfile(os.path.abspath(f)) |
|
96 |
path = os.path.abspath(f) |
|
97 |
old_settings = Setting.Catalogs['defaults'] |
|
98 |
new_settings = Setting.load_settings_from_file(path, old_settings) |
|
99 |
|
|
100 |
Setting.load_configuration(new_settings, |
|
101 |
source=path, |
|
102 |
allow_known=allow_known, |
|
103 |
allow_unknown=allow_unknown, |
|
104 |
allow_override=allow_override) |
|
74 | 105 |
except Exception as e: |
75 |
print >> sys.stderr, "Failed to read settings file: %s [%r]" % \ |
|
76 |
(os.path.abspath(f), e) |
|
106 |
print >> stderr, "Failed to read settings file: %s [%r]" % \ |
|
107 |
(path, e) |
|
108 |
raise |
|
77 | 109 |
raise SystemExit(1) |
78 | 110 |
|
111 |
Setting.configure_settings() |
|
112 |
_module.__dict__.update(Setting.Catalogs['runtime']) |
|
79 | 113 |
|
80 |
import sys |
|
81 |
from .setup import postproc_settings |
|
82 |
postproc_settings(sys.modules[__name__]) |
|
83 |
del postproc_settings |
|
84 |
|
|
85 |
for _module_path in SYNNEFO_SETTINGS_SETUP_MODULES: |
|
86 |
_temp = __import__(_module_path, globals(), locals(), |
|
87 |
['setup_settings'], 0) |
|
88 |
_temp.setup_settings(sys.modules[__name__]) |
|
89 |
|
|
90 |
del _temp |
|
91 |
del _module_path |
|
114 |
# cleanup module namespace |
|
115 |
for _name in dir(_module): |
|
116 |
if _name.startswith('_') or _name.isupper(): |
|
117 |
continue |
|
118 |
delattr(_module, _name) |
|
119 |
del _name |
|
120 |
del _module |
Also available in: Unified diff