Browse Source

Parameters the storage path of files depot.

Adrien Panay 7 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,8 +34,8 @@ use = egg:tracim
34 34
 full_stack = true
35 35
 # You can set french as default language by uncommenting next line
36 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 39
 beaker.session.key = tracim
40 40
 beaker.session.secret = 3283411b-1904-4554-b0e1-883863b53080
41 41
 
@@ -222,6 +222,9 @@ wsgidav.config_path = wsgidav.conf
222 222
 ## Do not set http:// prefix.
223 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 230
 # All configuration below is about logging.

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

@@ -13,10 +13,10 @@ convert them into boolean, for example, you should use the
13 13
 
14 14
 """
15 15
 import imp
16
-import importlib
17 16
 import os
18 17
 from urllib.parse import urlparse
19 18
 
19
+from depot.manager import DepotManager
20 20
 import tg
21 21
 from paste.deploy.converters import asbool
22 22
 from tg.configuration.milestones import environment_loaded
@@ -28,7 +28,6 @@ from tracim.lib.system import InterruptManager
28 28
 from tracim.lib.utils import lazy_ugettext as l_
29 29
 
30 30
 import tracim
31
-from tracim import model
32 31
 from tracim.config import TracimAppConfig
33 32
 from tracim.lib.base import logger
34 33
 from tracim.lib.daemons import DaemonsManager
@@ -38,11 +37,6 @@ from tracim.lib.daemons import WsgiDavDaemon
38 37
 from tracim.model.data import ActionDescription
39 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 41
 base_config = TracimAppConfig()
48 42
 base_config.renderers = []
@@ -51,25 +45,28 @@ base_config.use_toscawidgets2 = True
51 45
 
52 46
 base_config.package = tracim
53 47
 
54
-#Enable json in expose
48
+# Enable json in expose
55 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 53
 base_config.renderers.append('genshi')
59 54
 
60
-#Set the default renderer
55
+# Set the default renderer
61 56
 base_config.default_renderer = 'mako'
62 57
 base_config.renderers.append('mako')
63
-#Configure the base SQLALchemy Setup
58
+# Configure the base SQLALchemy Setup
64 59
 base_config.use_sqlalchemy = True
65 60
 base_config.model = tracim.model
66 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 65
 base_config.auth_backend = 'sqlalchemy'
70 66
 
71 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 70
 base_config['flash.template'] = '''
74 71
 <div class="alert alert-${status}" style="margin-top: 1em;">
75 72
     <button type="button" class="close" data-dismiss="alert">&times;</button>
@@ -79,9 +76,20 @@ base_config['flash.template'] = '''
79 76
     </div>
80 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 94
 base_config['templating.genshi.name_constant_patch'] = True
87 95
 
@@ -91,11 +99,18 @@ base_config['templating.genshi.name_constant_patch'] = True
91 99
 base_config.sa_auth.cookie_secret = "3283411b-1904-4554-b0e1-883863b53080"
92 100
 
93 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 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 115
 daemons = DaemonsManager()
101 116
 
@@ -116,10 +131,25 @@ def start_daemons(manager: DaemonsManager):
116 131
     if cfg.EMAIL_PROCESSING_MODE == CFG.CST.ASYNC:
117 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 146
 environment_loaded.register(lambda: start_daemons(daemons))
147
+environment_loaded.register(lambda: configure_depot())
148
+
120 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 153
 duplicated_email_subject = l_('Password reset request')
124 154
 duplicated_email_body = l_('''
125 155
 We've received a request to reset the password for this account.
@@ -129,11 +159,21 @@ Please click this link to reset your password:
129 159
 
130 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 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 177
 # TODO - Integrate these translations into tgapp-resetpassword
138 178
 #
139 179
 
@@ -143,7 +183,6 @@ l_('Save new password')
143 183
 l_('Email address')
144 184
 l_('Send Request')
145 185
 
146
-
147 186
 l_('Password reset request sent')
148 187
 l_('Invalid password reset request')
149 188
 l_('Password reset request timed out')
@@ -159,6 +198,7 @@ Please click this link to reset your password:
159 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 202
 class CFG(object):
163 203
     """
164 204
     Singleton used for easy access to config file parameters
@@ -174,7 +214,8 @@ class CFG(object):
174 214
 
175 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 219
         :param key:
179 220
         :param value:
180 221
         :return:
@@ -183,7 +224,8 @@ class CFG(object):
183 224
                 ('URL' not in key or type(value) == str) and \
184 225
                 'CONTENT' not in key:
185 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 229
             # At the time of configuration setup, it can't be evaluated
188 230
             # We do not show CONTENT in order not to pollute log files
189 231
             logger.info(self, 'CONFIG: [ {} | {} ]'.format(key, value))
@@ -194,14 +236,19 @@ class CFG(object):
194 236
 
195 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 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 252
         self.WEBSITE_BASE_URL = tg.config.get('website.base_url', '')
206 253
         self.WEBSITE_SERVER_NAME = tg.config.get('website.server_name', None)
207 254
 
@@ -216,7 +263,8 @@ class CFG(object):
216 263
 
217 264
         self.WEBSITE_HOME_TAG_LINE = tg.config.get('website.home.tag_line', '')
218 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 269
         if tg.config.get('email.notification.from'):
222 270
             raise Exception(
@@ -229,8 +277,10 @@ class CFG(object):
229 277
             tg.config.get('email.notification.from.email')
230 278
         self.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = \
231 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 284
         self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_HTML = tg.config.get(
235 285
             'email.notification.created_account.template.html',
236 286
             './tracim/templates/mail/created_account_body_html.mak',
@@ -239,24 +289,32 @@ class CFG(object):
239 289
             'email.notification.created_account.template.text',
240 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 294
         self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_SUBJECT = tg.config.get(
244 295
             'email.notification.created_account.subject',
245 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 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 319
         self.EMAIL_NOTIFICATION_NOTIFIED_EVENTS = [
262 320
             ActionDescription.COMMENT,
@@ -274,12 +332,13 @@ class CFG(object):
274 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 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 342
         self.RADICALE_SERVER_FILE_SYSTEM_FOLDER = tg.config.get(
284 343
             'radicale.server.filesystem.folder',
285 344
             './radicale/collections',
@@ -337,7 +396,9 @@ class CFG(object):
337 396
             'wsgidav.config_path',
338 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 402
         self.wsgidav_config = imp.load_source(
342 403
             'wsgidav_config',
343 404
             self.WSGIDAV_CONFIG_PATH,
@@ -395,17 +456,16 @@ class CFG(object):
395 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 461
         js_tracker_file_path = tg.config.get('js_tracker_path', None)
400 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 466
                 data = js_file.read()
404
-            return data
405
-        else:
406
-            return ''
407
-
408
-
467
+            result = data
468
+        return result
409 469
 
410 470
     class CST(object):
411 471
         ASYNC = 'ASYNC'
@@ -414,6 +474,7 @@ class CFG(object):
414 474
         TREEVIEW_FOLDERS = 'folders'
415 475
         TREEVIEW_ALL = 'all'
416 476
 
477
+
417 478
 #######
418 479
 #
419 480
 # INFO - D.A. - 2014-11-05