Browse Source

Parameters the storage path of files depot.

Adrien Panay 8 years ago
parent
commit
80dbaa4d16
2 changed files with 124 additions and 60 deletions
  1. 5 2
      tracim/development.ini.base
  2. 119 58
      tracim/tracim/config/app_cfg.py

+ 5 - 2
tracim/development.ini.base View File

34
 full_stack = true
34
 full_stack = true
35
 # You can set french as default language by uncommenting next line
35
 # You can set french as default language by uncommenting next line
36
 # lang = fr
36
 # lang = fr
37
-cache_dir = %(here)s/data
38
-preview_cache_dir = /tmp/tracim/cache/previews/
37
+cache_dir = %(here)s/data/cache
38
+preview_cache_dir = %(here)s/data/cache/preview/
39
 beaker.session.key = tracim
39
 beaker.session.key = tracim
40
 beaker.session.secret = 3283411b-1904-4554-b0e1-883863b53080
40
 beaker.session.secret = 3283411b-1904-4554-b0e1-883863b53080
41
 
41
 
222
 ## Do not set http:// prefix.
222
 ## Do not set http:// prefix.
223
 # wsgidav.client.base_url = 127.0.0.1:<WSGIDAV_PORT>
223
 # wsgidav.client.base_url = 127.0.0.1:<WSGIDAV_PORT>
224
 
224
 
225
+## DEPOT
226
+depot_storage_path = %(here)s/data/depot/
227
+
225
 #####
228
 #####
226
 #
229
 #
227
 # All configuration below is about logging.
230
 # All configuration below is about logging.

+ 119 - 58
tracim/tracim/config/app_cfg.py View File

13
 
13
 
14
 """
14
 """
15
 import imp
15
 import imp
16
-import importlib
17
 import os
16
 import os
18
 from urllib.parse import urlparse
17
 from urllib.parse import urlparse
19
 
18
 
19
+from depot.manager import DepotManager
20
 import tg
20
 import tg
21
 from paste.deploy.converters import asbool
21
 from paste.deploy.converters import asbool
22
 from tg.configuration.milestones import environment_loaded
22
 from tg.configuration.milestones import environment_loaded
28
 from tracim.lib.utils import lazy_ugettext as l_
28
 from tracim.lib.utils import lazy_ugettext as l_
29
 
29
 
30
 import tracim
30
 import tracim
31
-from tracim import model
32
 from tracim.config import TracimAppConfig
31
 from tracim.config import TracimAppConfig
33
 from tracim.lib.base import logger
32
 from tracim.lib.base import logger
34
 from tracim.lib.daemons import DaemonsManager
33
 from tracim.lib.daemons import DaemonsManager
38
 from tracim.model.data import ActionDescription
37
 from tracim.model.data import ActionDescription
39
 from tracim.model.data import ContentType
38
 from tracim.model.data import ContentType
40
 
39
 
41
-from depot.manager import DepotManager
42
-DepotManager.configure(
43
-    'default',
44
-    {'depot.storage_path': '/tmp/depot_storage_path/'}
45
-)
46
 
40
 
47
 base_config = TracimAppConfig()
41
 base_config = TracimAppConfig()
48
 base_config.renderers = []
42
 base_config.renderers = []
51
 
45
 
52
 base_config.package = tracim
46
 base_config.package = tracim
53
 
47
 
54
-#Enable json in expose
48
+# Enable json in expose
55
 base_config.renderers.append('json')
49
 base_config.renderers.append('json')
56
-#Enable genshi in expose to have a lingua franca for extensions and pluggable apps
57
-#you can remove this if you don't plan to use it.
50
+# Enable genshi in expose to have a lingua franca for extensions and pluggable
51
+# apps
52
+# you can remove this if you don't plan to use it.
58
 base_config.renderers.append('genshi')
53
 base_config.renderers.append('genshi')
59
 
54
 
60
-#Set the default renderer
55
+# Set the default renderer
61
 base_config.default_renderer = 'mako'
56
 base_config.default_renderer = 'mako'
62
 base_config.renderers.append('mako')
57
 base_config.renderers.append('mako')
63
-#Configure the base SQLALchemy Setup
58
+# Configure the base SQLALchemy Setup
64
 base_config.use_sqlalchemy = True
59
 base_config.use_sqlalchemy = True
65
 base_config.model = tracim.model
60
 base_config.model = tracim.model
66
 base_config.DBSession = tracim.model.DBSession
61
 base_config.DBSession = tracim.model.DBSession
67
 
62
 
68
-# This value can be modified by tracim.lib.auth.wrapper.AuthConfigWrapper but have to be specified before
63
+# This value can be modified by tracim.lib.auth.wrapper.AuthConfigWrapper but
64
+# have to be specified before
69
 base_config.auth_backend = 'sqlalchemy'
65
 base_config.auth_backend = 'sqlalchemy'
70
 
66
 
71
 # base_config.flash.cookie_name
67
 # base_config.flash.cookie_name
72
-# base_config.flash.default_status -> Default message status if not specified (ok by default)
68
+# base_config.flash.default_status -> Default message status if not specified
69
+# (ok by default)
73
 base_config['flash.template'] = '''
70
 base_config['flash.template'] = '''
74
 <div class="alert alert-${status}" style="margin-top: 1em;">
71
 <div class="alert alert-${status}" style="margin-top: 1em;">
75
     <button type="button" class="close" data-dismiss="alert">&times;</button>
72
     <button type="button" class="close" data-dismiss="alert">&times;</button>
79
     </div>
76
     </div>
80
 </div>
77
 </div>
81
 '''
78
 '''
82
-# -> string.Template instance used as the flash template when rendered from server side, will receive $container_id, $message and $status variables.
83
-# flash.js_call -> javascript code which will be run when displaying the flash from javascript. Default is webflash.render(), you can use webflash.payload() to retrieve the message and show it with your favourite library.
84
-# flash.js_template -> string.Template instance used to replace full javascript support for flash messages. When rendering flash message for javascript usage the following code will be used instead of providing the standard webflash object. If you replace js_template you must also ensure cookie parsing and delete it for already displayed messages. The template will receive: $container_id, $cookie_name, $js_call variables.
79
+
80
+# -> string.Template instance used as the flash template when rendered from
81
+# server side, will receive $container_id, $message and $status variables.
82
+
83
+# flash.js_call -> javascript code which will be run when displaying the flash
84
+# from javascript. Default is webflash.render(), you can use webflash.payload()
85
+# to retrieve the message and show it with your favourite library.
86
+
87
+# flash.js_template -> string.Template instance used to replace full javascript
88
+# support for flash messages. When rendering flash message for javascript usage
89
+# the following code will be used instead of providing the standard webflash
90
+# object. If you replace js_template you must also ensure cookie parsing and
91
+# delete it for already displayed messages. The template will receive:
92
+# $container_id, $cookie_name, $js_call variables.
85
 
93
 
86
 base_config['templating.genshi.name_constant_patch'] = True
94
 base_config['templating.genshi.name_constant_patch'] = True
87
 
95
 
91
 base_config.sa_auth.cookie_secret = "3283411b-1904-4554-b0e1-883863b53080"
99
 base_config.sa_auth.cookie_secret = "3283411b-1904-4554-b0e1-883863b53080"
92
 
100
 
93
 # INFO - This is the way to specialize the resetpassword email properties
101
 # INFO - This is the way to specialize the resetpassword email properties
94
-# plug(base_config, 'resetpassword', None, mail_subject=reset_password_email_subject)
102
+# plug(base_config,
103
+#      'resetpassword',
104
+#      None,
105
+#      mail_subject=reset_password_email_subject)
95
 plug(base_config, 'resetpassword', 'reset_password')
106
 plug(base_config, 'resetpassword', 'reset_password')
96
 
107
 
97
-replace_template(base_config, 'resetpassword.templates.index', 'tracim.templates.reset_password_index')
98
-replace_template(base_config, 'resetpassword.templates.change_password', 'mako:tracim.templates.reset_password_change_password')
108
+replace_template(base_config,
109
+                 'resetpassword.templates.index',
110
+                 'tracim.templates.reset_password_index')
111
+replace_template(base_config,
112
+                 'resetpassword.templates.change_password',
113
+                 'mako:tracim.templates.reset_password_change_password')
99
 
114
 
100
 daemons = DaemonsManager()
115
 daemons = DaemonsManager()
101
 
116
 
116
     if cfg.EMAIL_PROCESSING_MODE == CFG.CST.ASYNC:
131
     if cfg.EMAIL_PROCESSING_MODE == CFG.CST.ASYNC:
117
         manager.run('mail_sender', MailSenderDaemon)
132
         manager.run('mail_sender', MailSenderDaemon)
118
 
133
 
134
+
135
+def configure_depot():
136
+    """
137
+    Configure Depot
138
+    """
139
+    depot_storage_name = 'default'
140
+    depot_storage_path = CFG.get_instance().DEPOT_STORAGE_PATH
141
+    depot_storage_settings = {'depot.storage_path': depot_storage_path}
142
+    DepotManager.configure(depot_storage_name,
143
+                           depot_storage_settings)
144
+
145
+
119
 environment_loaded.register(lambda: start_daemons(daemons))
146
 environment_loaded.register(lambda: start_daemons(daemons))
147
+environment_loaded.register(lambda: configure_depot())
148
+
120
 interrupt_manager = InterruptManager(os.getpid(), daemons_manager=daemons)
149
 interrupt_manager = InterruptManager(os.getpid(), daemons_manager=daemons)
121
 
150
 
122
-# Note: here are fake translatable strings that allow to translate messages for reset password email content
151
+# Note: here are fake translatable strings that allow to translate messages for
152
+# reset password email content
123
 duplicated_email_subject = l_('Password reset request')
153
 duplicated_email_subject = l_('Password reset request')
124
 duplicated_email_body = l_('''
154
 duplicated_email_body = l_('''
125
 We've received a request to reset the password for this account.
155
 We've received a request to reset the password for this account.
129
 
159
 
130
 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.
160
 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.
131
 ''')
161
 ''')
162
+duplicated_email_body = l_('''
163
+We've received a request to reset the password for this account.
164
+Please click this link to reset your password:
165
+
166
+%(password_reset_link)s
167
+
168
+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.
169
+''')
170
+import pudb; pu.db
132
 
171
 
133
 #######
172
 #######
134
 #
173
 #
135
 # INFO - D.A. - 2014-10-31
174
 # INFO - D.A. - 2014-10-31
136
-# The following code is a dirty way to integrate translation for resetpassword tgapp in tracim
175
+# The following code is a dirty way to integrate translation for resetpassword
176
+# tgapp in tracim
137
 # TODO - Integrate these translations into tgapp-resetpassword
177
 # TODO - Integrate these translations into tgapp-resetpassword
138
 #
178
 #
139
 
179
 
143
 l_('Email address')
183
 l_('Email address')
144
 l_('Send Request')
184
 l_('Send Request')
145
 
185
 
146
-
147
 l_('Password reset request sent')
186
 l_('Password reset request sent')
148
 l_('Invalid password reset request')
187
 l_('Invalid password reset request')
149
 l_('Password reset request timed out')
188
 l_('Password reset request timed out')
159
 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.
198
 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.
160
 ''')
199
 ''')
161
 
200
 
201
+
162
 class CFG(object):
202
 class CFG(object):
163
     """
203
     """
164
     Singleton used for easy access to config file parameters
204
     Singleton used for easy access to config file parameters
174
 
214
 
175
     def __setattr__(self, key, value):
215
     def __setattr__(self, key, value):
176
         """
216
         """
177
-        Log-ready setter. this is used for logging configuration (every parameter except password)
217
+        Log-ready setter. this is used for logging configuration (every
218
+        parameter except password)
178
         :param key:
219
         :param key:
179
         :param value:
220
         :param value:
180
         :return:
221
         :return:
183
                 ('URL' not in key or type(value) == str) and \
224
                 ('URL' not in key or type(value) == str) and \
184
                 'CONTENT' not in key:
225
                 'CONTENT' not in key:
185
             # We do not show PASSWORD for security reason
226
             # We do not show PASSWORD for security reason
186
-            # we do not show URL because the associated config uses tg.lurl() which is evaluated when at display time.
227
+            # we do not show URL because the associated config uses tg.lurl()
228
+            # which is evaluated when at display time.
187
             # At the time of configuration setup, it can't be evaluated
229
             # At the time of configuration setup, it can't be evaluated
188
             # We do not show CONTENT in order not to pollute log files
230
             # We do not show CONTENT in order not to pollute log files
189
             logger.info(self, 'CONFIG: [ {} | {} ]'.format(key, value))
231
             logger.info(self, 'CONFIG: [ {} | {} ]'.format(key, value))
194
 
236
 
195
     def __init__(self):
237
     def __init__(self):
196
 
238
 
197
-        self.PREVIEW_CACHE = str(tg.config.get('preview_cache_dir'))
239
+        self.DEPOT_STORAGE_PATH = tg.config.get('depot_storage_path')
240
+        self.PREVIEW_CACHE = tg.config.get('preview_cache_dir')
198
 
241
 
199
-        self.DATA_UPDATE_ALLOWED_DURATION = int(tg.config.get('content.update.allowed.duration', 0))
242
+        self.DATA_UPDATE_ALLOWED_DURATION = \
243
+            int(tg.config.get('content.update.allowed.duration', 0))
200
 
244
 
201
         self.WEBSITE_TITLE = tg.config.get('website.title', 'TRACIM')
245
         self.WEBSITE_TITLE = tg.config.get('website.title', 'TRACIM')
202
-        self.WEBSITE_HOME_TITLE_COLOR = tg.config.get('website.title.color', '#555')
203
-        self.WEBSITE_HOME_IMAGE_URL = tg.lurl('/assets/img/home_illustration.jpg')
204
-        self.WEBSITE_HOME_BACKGROUND_IMAGE_URL = tg.lurl('/assets/img/bg.jpg')
246
+        self.WEBSITE_HOME_TITLE_COLOR = \
247
+            tg.config.get('website.title.color', '#555')
248
+        self.WEBSITE_HOME_IMAGE_URL = \
249
+            tg.lurl('/assets/img/home_illustration.jpg')
250
+        self.WEBSITE_HOME_BACKGROUND_IMAGE_URL = \
251
+            tg.lurl('/assets/img/bg.jpg')
205
         self.WEBSITE_BASE_URL = tg.config.get('website.base_url', '')
252
         self.WEBSITE_BASE_URL = tg.config.get('website.base_url', '')
206
         self.WEBSITE_SERVER_NAME = tg.config.get('website.server_name', None)
253
         self.WEBSITE_SERVER_NAME = tg.config.get('website.server_name', None)
207
 
254
 
216
 
263
 
217
         self.WEBSITE_HOME_TAG_LINE = tg.config.get('website.home.tag_line', '')
264
         self.WEBSITE_HOME_TAG_LINE = tg.config.get('website.home.tag_line', '')
218
         self.WEBSITE_SUBTITLE = tg.config.get('website.home.subtitle', '')
265
         self.WEBSITE_SUBTITLE = tg.config.get('website.home.subtitle', '')
219
-        self.WEBSITE_HOME_BELOW_LOGIN_FORM = tg.config.get('website.home.below_login_form', '')
266
+        self.WEBSITE_HOME_BELOW_LOGIN_FORM = \
267
+            tg.config.get('website.home.below_login_form', '')
220
 
268
 
221
         if tg.config.get('email.notification.from'):
269
         if tg.config.get('email.notification.from'):
222
             raise Exception(
270
             raise Exception(
229
             tg.config.get('email.notification.from.email')
277
             tg.config.get('email.notification.from.email')
230
         self.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = \
278
         self.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = \
231
             tg.config.get('email.notification.from.default_label')
279
             tg.config.get('email.notification.from.default_label')
232
-        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_HTML = tg.config.get('email.notification.content_update.template.html')
233
-        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_TEXT = tg.config.get('email.notification.content_update.template.text')
280
+        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_HTML = \
281
+            tg.config.get('email.notification.content_update.template.html')
282
+        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_TEXT = \
283
+            tg.config.get('email.notification.content_update.template.text')
234
         self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_HTML = tg.config.get(
284
         self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_HTML = tg.config.get(
235
             'email.notification.created_account.template.html',
285
             'email.notification.created_account.template.html',
236
             './tracim/templates/mail/created_account_body_html.mak',
286
             './tracim/templates/mail/created_account_body_html.mak',
239
             'email.notification.created_account.template.text',
289
             'email.notification.created_account.template.text',
240
             './tracim/templates/mail/created_account_body_text.mak',
290
             './tracim/templates/mail/created_account_body_text.mak',
241
         )
291
         )
242
-        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_SUBJECT = tg.config.get('email.notification.content_update.subject')
292
+        self.EMAIL_NOTIFICATION_CONTENT_UPDATE_SUBJECT = \
293
+            tg.config.get('email.notification.content_update.subject')
243
         self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_SUBJECT = tg.config.get(
294
         self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_SUBJECT = tg.config.get(
244
             'email.notification.created_account.subject',
295
             'email.notification.created_account.subject',
245
             '[{website_title}] Created account',
296
             '[{website_title}] Created account',
246
         )
297
         )
247
-        self.EMAIL_NOTIFICATION_PROCESSING_MODE = tg.config.get('email.notification.processing_mode')
248
-
249
-
250
-        self.EMAIL_NOTIFICATION_ACTIVATED = asbool(tg.config.get('email.notification.activated'))
251
-        self.EMAIL_NOTIFICATION_SMTP_SERVER = tg.config.get('email.notification.smtp.server')
252
-        self.EMAIL_NOTIFICATION_SMTP_PORT = tg.config.get('email.notification.smtp.port')
253
-        self.EMAIL_NOTIFICATION_SMTP_USER = tg.config.get('email.notification.smtp.user')
254
-        self.EMAIL_NOTIFICATION_SMTP_PASSWORD = tg.config.get('email.notification.smtp.password')
298
+        self.EMAIL_NOTIFICATION_PROCESSING_MODE = \
299
+            tg.config.get('email.notification.processing_mode')
300
+
301
+        self.EMAIL_NOTIFICATION_ACTIVATED = \
302
+            asbool(tg.config.get('email.notification.activated'))
303
+        self.EMAIL_NOTIFICATION_SMTP_SERVER = \
304
+            tg.config.get('email.notification.smtp.server')
305
+        self.EMAIL_NOTIFICATION_SMTP_PORT = \
306
+            tg.config.get('email.notification.smtp.port')
307
+        self.EMAIL_NOTIFICATION_SMTP_USER = \
308
+            tg.config.get('email.notification.smtp.user')
309
+        self.EMAIL_NOTIFICATION_SMTP_PASSWORD = \
310
+            tg.config.get('email.notification.smtp.password')
255
 
311
 
256
         self.TRACKER_JS_PATH = tg.config.get('js_tracker_path')
312
         self.TRACKER_JS_PATH = tg.config.get('js_tracker_path')
257
-        self.TRACKER_JS_CONTENT = self.get_tracker_js_content(self.TRACKER_JS_PATH)
313
+        self.TRACKER_JS_CONTENT = \
314
+            self.get_tracker_js_content(self.TRACKER_JS_PATH)
258
 
315
 
259
-        self.WEBSITE_TREEVIEW_CONTENT = tg.config.get('website.treeview.content')
316
+        self.WEBSITE_TREEVIEW_CONTENT = \
317
+            tg.config.get('website.treeview.content')
260
 
318
 
261
         self.EMAIL_NOTIFICATION_NOTIFIED_EVENTS = [
319
         self.EMAIL_NOTIFICATION_NOTIFIED_EVENTS = [
262
             ActionDescription.COMMENT,
320
             ActionDescription.COMMENT,
274
             # ContentType.Folder -- Folder is skipped
332
             # ContentType.Folder -- Folder is skipped
275
         ]
333
         ]
276
 
334
 
277
-        self.RADICALE_SERVER_HOST = tg.config.get('radicale.server.host', '0.0.0.0')
278
-        self.RADICALE_SERVER_PORT = int(
279
-            tg.config.get('radicale.server.port', 5232)
280
-        )
335
+        self.RADICALE_SERVER_HOST = \
336
+            tg.config.get('radicale.server.host', '0.0.0.0')
337
+        self.RADICALE_SERVER_PORT = \
338
+            int(tg.config.get('radicale.server.port', 5232))
281
         # Note: Other parameters needed to work in SSL (cert file, etc)
339
         # Note: Other parameters needed to work in SSL (cert file, etc)
282
-        self.RADICALE_SERVER_SSL = asbool(tg.config.get('radicale.server.ssl', False))
340
+        self.RADICALE_SERVER_SSL = \
341
+            asbool(tg.config.get('radicale.server.ssl', False))
283
         self.RADICALE_SERVER_FILE_SYSTEM_FOLDER = tg.config.get(
342
         self.RADICALE_SERVER_FILE_SYSTEM_FOLDER = tg.config.get(
284
             'radicale.server.filesystem.folder',
343
             'radicale.server.filesystem.folder',
285
             './radicale/collections',
344
             './radicale/collections',
337
             'wsgidav.config_path',
396
             'wsgidav.config_path',
338
             'wsgidav.conf',
397
             'wsgidav.conf',
339
         )
398
         )
340
-        # TODO: Convert to importlib (cf http://stackoverflow.com/questions/41063938/use-importlib-instead-imp-for-non-py-file)
399
+
400
+        # TODO: Convert to importlib
401
+        # http://stackoverflow.com/questions/41063938/use-importlib-instead-imp-for-non-py-file
341
         self.wsgidav_config = imp.load_source(
402
         self.wsgidav_config = imp.load_source(
342
             'wsgidav_config',
403
             'wsgidav_config',
343
             self.WSGIDAV_CONFIG_PATH,
404
             self.WSGIDAV_CONFIG_PATH,
395
             0,
456
             0,
396
         ))
457
         ))
397
 
458
 
398
-    def get_tracker_js_content(self, js_tracker_file_path = None):
459
+    def get_tracker_js_content(self, js_tracker_file_path=None):
460
+        result = ''
399
         js_tracker_file_path = tg.config.get('js_tracker_path', None)
461
         js_tracker_file_path = tg.config.get('js_tracker_path', None)
400
         if js_tracker_file_path:
462
         if js_tracker_file_path:
401
-            logger.info(self, 'Reading JS tracking code from file {}'.format(js_tracker_file_path))
402
-            with open (js_tracker_file_path, 'r') as js_file:
463
+            info_log = 'Reading JS tracking code from file {}'
464
+            logger.info(self, info_log.format(js_tracker_file_path))
465
+            with open(js_tracker_file_path, 'r') as js_file:
403
                 data = js_file.read()
466
                 data = js_file.read()
404
-            return data
405
-        else:
406
-            return ''
407
-
408
-
467
+            result = data
468
+        return result
409
 
469
 
410
     class CST(object):
470
     class CST(object):
411
         ASYNC = 'ASYNC'
471
         ASYNC = 'ASYNC'
414
         TREEVIEW_FOLDERS = 'folders'
474
         TREEVIEW_FOLDERS = 'folders'
415
         TREEVIEW_ALL = 'all'
475
         TREEVIEW_ALL = 'all'
416
 
476
 
477
+
417
 #######
478
 #######
418
 #
479
 #
419
 # INFO - D.A. - 2014-11-05
480
 # INFO - D.A. - 2014-11-05