Pārlūkot izejas kodu

Homogenises the conf parsing in conf access singleton.

Adrien Panay 7 gadus atpakaļ
vecāks
revīzija
12d315e98b
1 mainītis faili ar 116 papildinājumiem un 75 dzēšanām
  1. 116 75
      tracim/tracim/config/app_cfg.py

+ 116 - 75
tracim/tracim/config/app_cfg.py Parādīt failu

@@ -35,7 +35,6 @@ from tracim.lib.utils import lazy_ugettext as l_
35 35
 from tracim.model.data import ActionDescription
36 36
 from tracim.model.data import ContentType
37 37
 
38
-
39 38
 base_config = TracimAppConfig()
40 39
 base_config.renderers = []
41 40
 base_config.use_toscawidgets = False
@@ -142,23 +141,10 @@ environment_loaded.register(lambda: configure_depot())
142 141
 
143 142
 interrupt_manager = InterruptManager(os.getpid(), daemons_manager=daemons)
144 143
 
145
-# Note: here are fake translatable strings that allow to translate messages for
146
-# reset password email content
147
-duplicated_email_subject = l_('Password reset request')
148
-duplicated_email_body = l_('''
149
-We've received a request to reset the password for this account.
150
-Please click this link to reset your password:
151
-
152
-%(password_reset_link)s
153
-
154
-If you no longer wish to make the above change, or if you did not initiate this request, please disregard and/or delete this e-mail.
155
-''')
156
-
157 144
 #######
158 145
 #
159 146
 # INFO - D.A. - 2014-10-31
160
-# The following code is a dirty way to integrate translation for resetpassword
161
-# tgapp in tracim
147
+# fake strings allowing to translate resetpassword tgapp.
162 148
 # TODO - Integrate these translations into tgapp-resetpassword
163 149
 #
164 150
 
@@ -168,6 +154,8 @@ l_('Save new password')
168 154
 l_('Email address')
169 155
 l_('Send Request')
170 156
 
157
+l_('Password reset request')
158
+
171 159
 l_('Password reset request sent')
172 160
 l_('Invalid password reset request')
173 161
 l_('Password reset request timed out')
@@ -200,8 +188,7 @@ class CFG(object):
200 188
         """
201 189
         Log-ready setter.
202 190
 
203
-        This is used for logging configuration (every parameter except
204
-        password)
191
+        Logs all configuration parameters except password.
205 192
         :param key:
206 193
         :param value:
207 194
         :return:
@@ -222,21 +209,40 @@ class CFG(object):
222 209
 
223 210
     def __init__(self):
224 211
         """Parse configuration file."""
225
-        self.DEPOT_STORAGE_DIR = tg.config.get('depot_storage_dir')
226
-        self.PREVIEW_CACHE_DIR = tg.config.get('preview_cache_dir')
227
-
228
-        self.DATA_UPDATE_ALLOWED_DURATION = \
229
-            int(tg.config.get('content.update.allowed.duration', 0))
230
-
231
-        self.WEBSITE_TITLE = tg.config.get('website.title', 'TRACIM')
232
-        self.WEBSITE_HOME_TITLE_COLOR = \
233
-            tg.config.get('website.title.color', '#555')
234
-        self.WEBSITE_HOME_IMAGE_URL = \
235
-            tg.lurl('/assets/img/home_illustration.jpg')
236
-        self.WEBSITE_HOME_BACKGROUND_IMAGE_URL = \
237
-            tg.lurl('/assets/img/bg.jpg')
238
-        self.WEBSITE_BASE_URL = tg.config.get('website.base_url', '')
239
-        self.WEBSITE_SERVER_NAME = tg.config.get('website.server_name', None)
212
+        self.DEPOT_STORAGE_DIR = tg.config.get(
213
+            'depot_storage_dir',
214
+        )
215
+        self.PREVIEW_CACHE_DIR = tg.config.get(
216
+            'preview_cache_dir',
217
+        )
218
+
219
+        self.DATA_UPDATE_ALLOWED_DURATION = int(tg.config.get(
220
+            'content.update.allowed.duration',
221
+            0,
222
+        ))
223
+
224
+        self.WEBSITE_TITLE = tg.config.get(
225
+            'website.title',
226
+            'TRACIM',
227
+        )
228
+        self.WEBSITE_HOME_TITLE_COLOR = tg.config.get(
229
+            'website.title.color',
230
+            '#555',
231
+        )
232
+        self.WEBSITE_HOME_IMAGE_URL = tg.lurl(
233
+            '/assets/img/home_illustration.jpg',
234
+        )
235
+        self.WEBSITE_HOME_BACKGROUND_IMAGE_URL = tg.lurl(
236
+            '/assets/img/bg.jpg',
237
+        )
238
+        self.WEBSITE_BASE_URL = tg.config.get(
239
+            'website.base_url',
240
+            '',
241
+        )
242
+        self.WEBSITE_SERVER_NAME = tg.config.get(
243
+            'website.server_name',
244
+            None,
245
+        )
240 246
 
241 247
         if not self.WEBSITE_SERVER_NAME:
242 248
             self.WEBSITE_SERVER_NAME = urlparse(self.WEBSITE_BASE_URL).hostname
@@ -247,10 +253,18 @@ class CFG(object):
247 253
                 .format(self.WEBSITE_SERVER_NAME)
248 254
             )
249 255
 
250
-        self.WEBSITE_HOME_TAG_LINE = tg.config.get('website.home.tag_line', '')
251
-        self.WEBSITE_SUBTITLE = tg.config.get('website.home.subtitle', '')
252
-        self.WEBSITE_HOME_BELOW_LOGIN_FORM = \
253
-            tg.config.get('website.home.below_login_form', '')
256
+        self.WEBSITE_HOME_TAG_LINE = tg.config.get(
257
+            'website.home.tag_line',
258
+            '',
259
+        )
260
+        self.WEBSITE_SUBTITLE = tg.config.get(
261
+            'website.home.subtitle',
262
+            '',
263
+        )
264
+        self.WEBSITE_HOME_BELOW_LOGIN_FORM = tg.config.get(
265
+            'website.home.below_login_form',
266
+            '',
267
+        )
254 268
 
255 269
         if tg.config.get('email.notification.from'):
256 270
             raise Exception(
@@ -259,14 +273,18 @@ class CFG(object):
259 273
                 'email.notification.from.default_label.'
260 274
             )
261 275
 
262
-        self.EMAIL_NOTIFICATION_FROM_EMAIL = \
263
-            tg.config.get('email.notification.from.email')
264
-        self.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = \
265
-            tg.config.get('email.notification.from.default_label')
266
-        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_HTML = \
267
-            tg.config.get('email.notification.content_update.template.html')
268
-        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_TEXT = \
269
-            tg.config.get('email.notification.content_update.template.text')
276
+        self.EMAIL_NOTIFICATION_FROM_EMAIL = tg.config.get(
277
+            'email.notification.from.email',
278
+        )
279
+        self.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = tg.config.get(
280
+            'email.notification.from.default_label'
281
+        )
282
+        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_HTML = tg.config.get(
283
+            'email.notification.content_update.template.html',
284
+        )
285
+        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_TEXT = tg.config.get(
286
+            'email.notification.content_update.template.text',
287
+        )
270 288
         self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_HTML = tg.config.get(
271 289
             'email.notification.created_account.template.html',
272 290
             './tracim/templates/mail/created_account_body_html.mak',
@@ -275,32 +293,43 @@ class CFG(object):
275 293
             'email.notification.created_account.template.text',
276 294
             './tracim/templates/mail/created_account_body_text.mak',
277 295
         )
278
-        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_SUBJECT = \
279
-            tg.config.get('email.notification.content_update.subject')
296
+        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_SUBJECT = tg.config.get(
297
+            'email.notification.content_update.subject',
298
+        )
280 299
         self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_SUBJECT = tg.config.get(
281 300
             'email.notification.created_account.subject',
282 301
             '[{website_title}] Created account',
283 302
         )
284
-        self.EMAIL_NOTIFICATION_PROCESSING_MODE = \
285
-            tg.config.get('email.notification.processing_mode')
303
+        self.EMAIL_NOTIFICATION_PROCESSING_MODE = tg.config.get(
304
+            'email.notification.processing_mode',
305
+        )
286 306
 
287
-        self.EMAIL_NOTIFICATION_ACTIVATED = \
288
-            asbool(tg.config.get('email.notification.activated'))
289
-        self.EMAIL_NOTIFICATION_SMTP_SERVER = \
290
-            tg.config.get('email.notification.smtp.server')
291
-        self.EMAIL_NOTIFICATION_SMTP_PORT = \
292
-            tg.config.get('email.notification.smtp.port')
293
-        self.EMAIL_NOTIFICATION_SMTP_USER = \
294
-            tg.config.get('email.notification.smtp.user')
295
-        self.EMAIL_NOTIFICATION_SMTP_PASSWORD = \
296
-            tg.config.get('email.notification.smtp.password')
307
+        self.EMAIL_NOTIFICATION_ACTIVATED = asbool(tg.config.get(
308
+            'email.notification.activated',
309
+        ))
310
+        self.EMAIL_NOTIFICATION_SMTP_SERVER = tg.config.get(
311
+            'email.notification.smtp.server',
312
+        )
313
+        self.EMAIL_NOTIFICATION_SMTP_PORT = tg.config.get(
314
+            'email.notification.smtp.port',
315
+        )
316
+        self.EMAIL_NOTIFICATION_SMTP_USER = tg.config.get(
317
+            'email.notification.smtp.user',
318
+        )
319
+        self.EMAIL_NOTIFICATION_SMTP_PASSWORD = tg.config.get(
320
+            'email.notification.smtp.password',
321
+        )
297 322
 
298
-        self.TRACKER_JS_PATH = tg.config.get('js_tracker_path')
299
-        self.TRACKER_JS_CONTENT = \
300
-            self.get_tracker_js_content(self.TRACKER_JS_PATH)
323
+        self.TRACKER_JS_PATH = tg.config.get(
324
+            'js_tracker_path',
325
+        )
326
+        self.TRACKER_JS_CONTENT = self.get_tracker_js_content(
327
+            self.TRACKER_JS_PATH,
328
+        )
301 329
 
302
-        self.WEBSITE_TREEVIEW_CONTENT = \
303
-            tg.config.get('website.treeview.content')
330
+        self.WEBSITE_TREEVIEW_CONTENT = tg.config.get(
331
+            'website.treeview.content',
332
+        )
304 333
 
305 334
         self.EMAIL_NOTIFICATION_NOTIFIED_EVENTS = [
306 335
             ActionDescription.COMMENT,
@@ -318,13 +347,19 @@ class CFG(object):
318 347
             # ContentType.Folder -- Folder is skipped
319 348
         ]
320 349
 
321
-        self.RADICALE_SERVER_HOST = \
322
-            tg.config.get('radicale.server.host', '0.0.0.0')
323
-        self.RADICALE_SERVER_PORT = \
324
-            int(tg.config.get('radicale.server.port', 5232))
350
+        self.RADICALE_SERVER_HOST = tg.config.get(
351
+            'radicale.server.host',
352
+            '0.0.0.0',
353
+        )
354
+        self.RADICALE_SERVER_PORT = int(tg.config.get(
355
+            'radicale.server.port',
356
+            5232,
357
+        ))
325 358
         # Note: Other parameters needed to work in SSL (cert file, etc)
326
-        self.RADICALE_SERVER_SSL = \
327
-            asbool(tg.config.get('radicale.server.ssl', False))
359
+        self.RADICALE_SERVER_SSL = asbool(tg.config.get(
360
+            'radicale.server.ssl',
361
+            False,
362
+        ))
328 363
         self.RADICALE_SERVER_FILE_SYSTEM_FOLDER = tg.config.get(
329 364
             'radicale.server.filesystem.folder',
330 365
             './radicale/collections',
@@ -347,11 +382,15 @@ class CFG(object):
347 382
             'Tracim Calendar - Password Required',
348 383
         )
349 384
 
350
-        self.RADICALE_CLIENT_BASE_URL_HOST = \
351
-            tg.config.get('radicale.client.base_url.host', None)
385
+        self.RADICALE_CLIENT_BASE_URL_HOST = tg.config.get(
386
+            'radicale.client.base_url.host',
387
+            None,
388
+        )
352 389
 
353
-        self.RADICALE_CLIENT_BASE_URL_PREFIX = \
354
-            tg.config.get('radicale.client.base_url.prefix', '/')
390
+        self.RADICALE_CLIENT_BASE_URL_PREFIX = tg.config.get(
391
+            'radicale.client.base_url.prefix',
392
+            '/',
393
+        )
355 394
         # Ensure finished by '/'
356 395
         if '/' != self.RADICALE_CLIENT_BASE_URL_PREFIX[-1]:
357 396
             self.RADICALE_CLIENT_BASE_URL_PREFIX += '/'
@@ -390,8 +429,10 @@ class CFG(object):
390 429
             self.WSGIDAV_CONFIG_PATH,
391 430
         )
392 431
         self.WSGIDAV_PORT = self.wsgidav_config.port
393
-        self.WSGIDAV_CLIENT_BASE_URL = \
394
-            tg.config.get('wsgidav.client.base_url', None)
432
+        self.WSGIDAV_CLIENT_BASE_URL = tg.config.get(
433
+            'wsgidav.client.base_url',
434
+            None,
435
+        )
395 436
 
396 437
         if not self.WSGIDAV_CLIENT_BASE_URL:
397 438
             self.WSGIDAV_CLIENT_BASE_URL = \