1
|
import os
|
2
|
|
3
|
from ConfigParser import SafeConfigParser
|
4
|
from mandaye.exceptions import ImproperlyConfigured
|
5
|
|
6
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
7
|
|
8
|
# get configuration files from :
|
9
|
# 1. default-settings.ini from source code
|
10
|
# 2. from MANDAYE_CONFIG_FILE environ variable
|
11
|
SETTINGS_INI = [os.path.join(BASE_DIR, 'default-config.ini')]
|
12
|
if 'MANDAYE_CONFIG_FILES' in os.environ:
|
13
|
print 'Loading setting files %r' % os.environ['MANDAYE_CONFIG_FILES']
|
14
|
SETTINGS_INI += os.environ['MANDAYE_CONFIG_FILES'].split(' ')
|
15
|
config = SafeConfigParser()
|
16
|
config.read(SETTINGS_INI)
|
17
|
|
18
|
|
19
|
def section2dict(section):
|
20
|
res = dict()
|
21
|
if config.has_section(section):
|
22
|
for opt in config.options(section):
|
23
|
res[opt] = config.get(section, opt)
|
24
|
return res
|
25
|
|
26
|
## SQL Backend config
|
27
|
# Database configuration
|
28
|
# dialect+driver://username:password@host:port/database
|
29
|
db_url = config.get('database', 'url')
|
30
|
|
31
|
## LDAP Backend config
|
32
|
ldap_url = config.get('ldap', 'url')
|
33
|
ldap_bind_dn = config.get('ldap', 'bind_dn')
|
34
|
ldap_bind_password = config.get('ldap', 'bind_password')
|
35
|
ldap_base_dn = config.get('ldap', 'base_dn')
|
36
|
|
37
|
debug = config.getboolean('debug', 'debug')
|
38
|
|
39
|
# Log configuration
|
40
|
logger_name = config.get('debug', 'logger_name')
|
41
|
LOGGING = {
|
42
|
'version': 1,
|
43
|
'disable_existing_loggers': True,
|
44
|
|
45
|
'formatters': {
|
46
|
'console': {
|
47
|
'format': '%(asctime)s %(levelname)s %(message)s',
|
48
|
'datefmt': '%H:%M:%S',
|
49
|
},
|
50
|
'syslog': {
|
51
|
'format': 'mandaye(pid=%(process)d) %(name)s %(levelname)s %(uuid)s %(message)s',
|
52
|
'datefmt': '%Y-%m-%d %H:%M:%S'
|
53
|
}
|
54
|
},
|
55
|
'handlers': {
|
56
|
'console': {
|
57
|
'level': 'DEBUG',
|
58
|
'class': 'logging.StreamHandler',
|
59
|
'formatter': 'console'
|
60
|
},
|
61
|
'syslog': {
|
62
|
'level': 'DEBUG',
|
63
|
'class': 'entrouvert.logging.handlers.SysLogHandler',
|
64
|
'formatter': 'syslog',
|
65
|
'address': '/dev/log'
|
66
|
},
|
67
|
},
|
68
|
'loggers': {
|
69
|
'': {
|
70
|
'handlers': ['console'],
|
71
|
'level': 'INFO',
|
72
|
'propagate': False,
|
73
|
},
|
74
|
'mandaye': {
|
75
|
'handlers': ['console', 'syslog'],
|
76
|
'level': 'INFO',
|
77
|
'propagate': False,
|
78
|
},
|
79
|
logger_name: {
|
80
|
'handlers': ['console', 'syslog'],
|
81
|
'level': 'INFO',
|
82
|
'propagate': False,
|
83
|
},
|
84
|
},
|
85
|
}
|
86
|
|
87
|
if config.getboolean('debug', 'log_debug'):
|
88
|
LOGGING['loggers']['']['level'] = 'DEBUG'
|
89
|
LOGGING['loggers']['mandaye']['level'] = 'DEBUG'
|
90
|
LOGGING['loggers'][logger_name]['level'] = 'DEBUG'
|
91
|
|
92
|
## PATH
|
93
|
# Configuration directory
|
94
|
config_root = config.get('dirs', 'config_root')
|
95
|
template_directory = os.path.join(BASE_DIR, 'templates')
|
96
|
# Templates directories
|
97
|
templates_directories = []
|
98
|
if config.get('dirs', 'templates_directories'):
|
99
|
templates_directories = config.get('dirs', 'templates_directories').split(' ')
|
100
|
templates_directories.append(os.path.join(BASE_DIR, 'templates'))
|
101
|
# Static url
|
102
|
static_url = config.get('dirs', 'static_url')
|
103
|
# Static folder
|
104
|
static_root = config.get('dirs', 'static_root')
|
105
|
# Data dir
|
106
|
data_dir = config.get('dirs', 'data_dir')
|
107
|
skel_root = os.path.join(BASE_DIR, 'skel')
|
108
|
|
109
|
# template vars
|
110
|
template_vars = section2dict('template_vars')
|
111
|
|
112
|
# Supported authentification
|
113
|
authentifications = section2dict('authentifications')
|
114
|
|
115
|
# sp mappers
|
116
|
mappers = section2dict('mappers')
|
117
|
|
118
|
# Raven Sentry configuration
|
119
|
raven_dsn = config.get('debug', 'sentry_dsn')
|
120
|
|
121
|
# Email notification configuration
|
122
|
email_notification = config.getboolean('email', 'notification')
|
123
|
email_prefix = config.get('email', 'prefix')
|
124
|
smtp_host = config.get('email', 'smtp_host')
|
125
|
smtp_port = config.getint('email', 'smtp_port')
|
126
|
email_from = config.get('email', 'from')
|
127
|
email_to = config.get('email', 'to').split()
|
128
|
|
129
|
# Alembic configuration
|
130
|
alembic_cfg = os.path.join(BASE_DIR, 'alembic.ini')
|
131
|
alembic_script_path = os.path.join(BASE_DIR, 'alembic')
|
132
|
|
133
|
# Use long traceback with xtraceback
|
134
|
use_long_trace = config.getboolean('debug', 'use_long_trace')
|
135
|
# Ask Mandaye to auto decompress a response message
|
136
|
# Decompress response only if you load a filter
|
137
|
auto_decompress = config.getboolean('mandaye', 'auto_decompress')
|
138
|
# Ask mandaye to add a toolbar with Mandaye's links
|
139
|
mandaye_toolbar = config.getboolean('mandaye', 'toolbar')
|
140
|
mandaye_offline_toolbar = config.getboolean('mandaye', 'offline_toolbar')
|
141
|
# Authentic 2 auto connection
|
142
|
a2_auto_connection = config.getboolean('mandaye', 'a2_auto_connection')
|
143
|
|
144
|
# Choose storage (sql or ldap)
|
145
|
if config.get('mandaye', 'storage_backend') == 'sql':
|
146
|
storage_backend = "mandaye.backends.sql"
|
147
|
elif config.get('mandaye', 'storage_backend') == 'ldap':
|
148
|
storage_backend = "mandaye.backends.ldap_back"
|
149
|
else:
|
150
|
ImproperlyConfigured('Storage backend must be sql or ldap')
|
151
|
|
152
|
# Encrypt service provider passwords with a secret
|
153
|
# You should install pycypto to use this feature
|
154
|
encrypt_sp_password = config.getboolean('mandaye', 'encrypt_sp_password')
|
155
|
# Must be a 15, 24, or 32 bytes long
|
156
|
encrypt_secret = config.get('mandaye', 'encrypt_secret')
|
157
|
|
158
|
session_type = config.get('session', 'type')
|
159
|
if session_type not in ('file', 'dbm', 'memory', 'memcached'):
|
160
|
raise ImproperlyConfigured('Sesssion type %r not supported' % session_type)
|
161
|
if session_type == 'memcached':
|
162
|
session_type = 'ext:memcached'
|
163
|
|
164
|
# Beaker session configuration
|
165
|
session_opts = {
|
166
|
'session.type': session_type,
|
167
|
'session.url': config.get('session', 'url'),
|
168
|
'session.cookie_expires': config.getboolean('session', 'cookie_expires'),
|
169
|
'session.timeout': config.getint('session', 'timeout'),
|
170
|
'session.data_dir': config.get('session', 'data_dir')
|
171
|
}
|
172
|
|
173
|
# Import local config
|
174
|
try:
|
175
|
from local_config import *
|
176
|
except ImportError, e:
|
177
|
if not 'local_config' in e.args[0]:
|
178
|
raise ImproperlyConfigured('Error while importing "local_config.py"')
|
179
|
|