Projet

Général

Profil

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

root / mandaye / skel / example.module / config.py @ 9f6ed9fb

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
# Supported authentification
103
authentifications = {{
104
    'saml2': 'mandaye.auth.saml2.SAML2Auth'
105
}}
106

    
107
# sp mappers
108
mappers = {{
109
    'linuxfr': '{project_name}.mappers.linuxfr_example',
110
}}
111

    
112
# Raven Sentry configuration
113
raven_dsn = config.get('debug', 'sentry_dsn')
114

    
115
# Email notification configuration
116
email_notification = config.getboolean('email', 'notification')
117
email_prefix = config.get('email', 'prefix')
118
smtp_host = config.get('email', 'smtp_host')
119
smtp_port = config.getint('email', 'smtp_port')
120
email_from = config.get('email', 'from')
121
email_to = config.get('email', 'to').split()
122

    
123
# Use long traceback with xtraceback
124
use_long_trace = config.getboolean('debug', 'use_long_trace')
125
# Ask Mandaye to auto decompress a response message
126
# Decompress response only if you load a filter
127
auto_decompress = config.getboolean('mandaye', 'auto_decompress')
128
# Ask mandaye to add a toolbar with Mandaye's links
129
mandaye_toolbar = config.getboolean('mandaye', 'toolbar')
130
# Authentic 2 auto connection
131
a2_auto_connection = config.getboolean('mandaye', 'a2_auto_connection')
132

    
133
# Choose storage
134
# Only mandaye.backends.sql at the moment
135
if config.get('mandaye', 'storage_backend') == 'sql':
136
    storage_backend = "mandaye.backends.sql"
137
else:
138
    ImproperlyConfigured('Storage backend must be sql')
139

    
140
# Encrypt service provider passwords with a secret
141
# You should install pycypto to use this feature
142
encrypt_sp_password = config.getboolean('mandaye', 'encrypt_sp_password')
143
# Must be a 15, 24, or 32 bytes long
144
encrypt_secret = config.get('mandaye', 'encrypt_secret')
145

    
146
session_type = config.get('session', 'type')
147
if session_type not in ('file', 'dbm', 'memory', 'memcached'):
148
    raise ImproperlyConfigured('Sesssion type %r not supported' % session_type)
149
if session_type == 'memcached':
150
    session_type = 'ext:memcached'
151

    
152
# Beaker session configuration
153
session_opts = {{
154
    'session.type': session_type,
155
    'session.url': config.get('session', 'url'),
156
    'session.cookie_expires': config.getboolean('session', 'cookie_expires'),
157
    'session.timeout': config.getint('session', 'timeout'),
158
    'session.data_dir': config.get('session', 'data_dir')
159
}}
160

    
161
# Import local config
162
try:
163
    from cam.local_config import *
164
except ImportError, e:
165
    if not 'local_config' in e.args[0]:
166
        raise ImproperlyConfigured('Error while importing "local_config.py"')
167

    
(2-2/4)