Projet

Général

Profil

Télécharger (5,7 ko) Statistiques
| Branche: | Tag: | Révision:

root / mandaye / skel / example.module / config.py @ 8f7e157d

1
import logging
2
import os
3

    
4
from ConfigParser import SafeConfigParser
5
from mandaye.exceptions import ImproperlyConfigured
6

    
7
# get configuration files from :
8
# 1. default-settings.ini from source code
9
# 2. os.environ.get('SETTINGS_INI') if it exists
10
#    else /etc/mandaye-cam/config.ini
11
#         and then /etc/mandaye-cam/local-config.ini
12
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
13
SETTINGS_INI = (os.path.join(BASE_DIR, 'default-config.ini'),)
14
if os.environ.get('SETTINGS_INI'):
15
    SETTINGS_INI += (os.environ.get('SETTINGS_INI'),)
16
else:
17
    ETC_DIR = os.path.join('/', 'etc', 'mandaye-cam')
18
    SETTINGS_INI += (
19
        os.path.join(ETC_DIR, 'config.ini'),
20
        os.path.join(ETC_DIR, 'local-config.ini')
21
    )
22

    
23
config = SafeConfigParser()
24
config.read(SETTINGS_INI)
25

    
26
## SQL Backend config
27
# Database configuration
28
# http://docs.sqlalchemy.org/en/rel_0_7/core/engines.html
29
# rfc 1738 https://tools.ietf.org/html/rfc1738
30
# dialect+driver://username:password@host:port/database
31
db_url = config.get('database', 'url')
32

    
33
debug = config.getboolean('debug', 'debug')
34

    
35
# Log configuration
36
LOGGING = {{
37
        'version': 1,
38
        'disable_existing_loggers': True,
39

    
40
        'formatters': {{
41
            'console': {{
42
                'format': '%(asctime)s %(levelname)s %(message)s',
43
                'datefmt': '%H:%M:%S',
44
                }},
45
            'file': {{
46
                'format': '%(asctime)s %(levelname)s %(uuid)s %(message)s',
47
                'datefmt': '%Y-%m-%d %H:%M:%S'
48
                }}
49
            }},
50
        'handlers': {{
51
            'console': {{
52
                'level': 'DEBUG',
53
                'class': 'logging.StreamHandler',
54
                'formatter': 'console'
55
                }},
56
            'syslog': {{
57
                'level': 'DEBUG',
58
                'class': 'entrouvert.logging.handlers.SysLogHandler',
59
                'formatter': 'file',
60
                'address': '/dev/log'
61
                }},
62
            }},
63
        'loggers': {{
64
            '': {{
65
                'handlers': ['console'],
66
                'level': 'INFO',
67
                'propagate': False,
68
                }},
69
            'mandaye': {{
70
                'handlers': ['console', 'syslog'],
71
                'level': 'INFO',
72
                'propagate': False,
73
                }},
74
            'cam': {{
75
                'handlers': ['console', 'syslog'],
76
                'level': 'INFO',
77
                'propagate': False,
78
                }},
79
            }},
80
        }}
81

    
82
if config.getboolean('debug', 'log_debug'):
83
    LOGGING['loggers']['']['level'] = 'DEBUG'
84
    LOGGING['loggers']['mandaye']['level'] = 'DEBUG'
85
    LOGGING['loggers']['cam']['level'] = 'DEBUG'
86

    
87
## PATH
88
# Configuration directory
89
config_root = config.get('dirs', 'config_root')
90
# Templates directories
91
templates_directories = []
92
if config.get('dirs', 'templates_directories'):
93
    templates_directories = config.get('dirs', 'templates_directories').split(' ')
94
templates_directories.append(os.path.join(BASE_DIR, 'templates'))
95
# Static url
96
static_url = config.get('dirs', 'static_url')
97
# Static folder
98
static_root = config.get('dirs', 'static_root')
99
# Data dir
100
data_dir = config.get('dirs', 'data_dir')
101

    
102
# template vars
103
template_vars = {{}}
104
if config.has_section('template_vars'):
105
    for option in config.options('template_vars'):
106
        template_vars[option] = config.get('template_vars', option)
107

    
108
# Supported authentification
109
authentifications = {{
110
    'saml2': 'mandaye.auth.saml2.SAML2Auth'
111
}}
112

    
113
# sp mappers
114
mappers = {{
115
    'linuxfr': '{project_name}.mappers.linuxfr_example',
116
}}
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
# Use long traceback with xtraceback
130
use_long_trace = config.getboolean('debug', 'use_long_trace')
131
# Ask Mandaye to auto decompress a response message
132
# Decompress response only if you load a filter
133
auto_decompress = config.getboolean('mandaye', 'auto_decompress')
134
# Ask mandaye to add a toolbar with Mandaye's links
135
mandaye_toolbar = config.getboolean('mandaye', 'toolbar')
136
mandaye_toolbar_offline = config.getboolean('mandaye', 'offline_toolbar')
137
# Authentic 2 auto connection
138
a2_auto_connection = config.getboolean('mandaye', 'a2_auto_connection')
139

    
140
# Choose storage
141
# Only mandaye.backends.sql at the moment
142
if config.get('mandaye', 'storage_backend') == 'sql':
143
    storage_backend = "mandaye.backends.sql"
144
else:
145
    ImproperlyConfigured('Storage backend must be sql')
146

    
147
# Encrypt service provider passwords with a secret
148
# You should install pycypto to use this feature
149
encrypt_sp_password = config.getboolean('mandaye', 'encrypt_sp_password')
150
# Must be a 15, 24, or 32 bytes long
151
encrypt_secret = config.get('mandaye', 'encrypt_secret')
152

    
153
session_type = config.get('session', 'type')
154
if session_type not in ('file', 'dbm', 'memory', 'memcached'):
155
    raise ImproperlyConfigured('Sesssion type %r not supported' % session_type)
156
if session_type == 'memcached':
157
    session_type = 'ext:memcached'
158

    
159
# Beaker session configuration
160
session_opts = {{
161
    'session.type': session_type,
162
    'session.url': config.get('session', 'url'),
163
    'session.cookie_expires': config.getboolean('session', 'cookie_expires'),
164
    'session.timeout': config.getint('session', 'timeout'),
165
    'session.data_dir': config.get('session', 'data_dir'),
166
    'session.path': '/'
167
}}
168

    
169
# Import local config
170
try:
171
    from cam.local_config import *
172
except ImportError, e:
173
    if not 'local_config' in e.args[0]:
174
        raise ImproperlyConfigured('Error while importing "local_config.py"')
175

    
(2-2/4)