Parcourir la source

Merge pull request #313 from tracim/fix/311/set_depot_from_config

Bastien Sevajol il y a 7 ans
Parent
révision
79b4d22800

+ 3 - 2
tracim/development.ini.base Voir le fichier

@@ -33,12 +33,13 @@ cookie_secret = 3283411b-1904-4554-b0e1-883863b53080
33 33
 use = egg:tracim
34 34
 full_stack = true
35 35
 # You can set french as default language by uncommenting next line
36
-# lang = fr
36
+# i18n.lang = fr
37 37
 
38 38
 cache_dir = %(here)s/data
39 39
 # preview generator cache directory
40 40
 preview_cache_dir = /tmp/tracim/preview/
41
-# file depot storage directory
41
+# file depot storage
42
+depot_storage_name = tracim
42 43
 depot_storage_dir = %(here)s/depot/
43 44
 
44 45
 beaker.session.key = tracim

+ 16 - 6
tracim/migration/versions/913efdf409e5_all_files_also_on_disk.py Voir le fichier

@@ -8,6 +8,7 @@ Create Date: 2017-07-12 15:44:20.568447
8 8
 
9 9
 import shutil
10 10
 
11
+from alembic import context
11 12
 from alembic import op
12 13
 from depot.fields.sqlalchemy import UploadedFileField
13 14
 from depot.fields.upload import UploadedFile
@@ -34,6 +35,17 @@ revision_helper = sa.Table(
34 35
 )
35 36
 
36 37
 
38
+def configure_depot():
39
+    """Configure Depot."""
40
+    depot_storage_name = context.config.get_main_option('depot_storage_name')
41
+    depot_storage_path = context.config.get_main_option('depot_storage_dir')
42
+    depot_storage_settings = {'depot.storage_path': depot_storage_path}
43
+    DepotManager.configure(
44
+        depot_storage_name,
45
+        depot_storage_settings,
46
+    )
47
+
48
+
37 49
 def delete_files_on_disk(connection: sa.engine.Connection):
38 50
     """Deletes files from disk and their references in database."""
39 51
     delete_query = revision_helper.update() \
@@ -41,7 +53,8 @@ def delete_files_on_disk(connection: sa.engine.Connection):
41 53
         .where(revision_helper.c.depot_file.isnot(None)) \
42 54
         .values(depot_file=None)
43 55
     connection.execute(delete_query)
44
-    shutil.rmtree('depot/', ignore_errors=True)
56
+    depot_storage_path = context.config.get_main_option('depot_storage_dir')
57
+    shutil.rmtree(depot_storage_path, ignore_errors=True)
45 58
 
46 59
 
47 60
 def upgrade():
@@ -55,9 +68,7 @@ def upgrade():
55 68
     - create all files on disk from database.
56 69
     """
57 70
     # Creates files depot used in this migration
58
-    DepotManager.configure(
59
-        'tracim', {'depot.storage_path': 'depot/'},
60
-    )
71
+    configure_depot()
61 72
     connection = op.get_bind()
62 73
     delete_files_on_disk(connection=connection)
63 74
     select_query = revision_helper.select() \
@@ -78,8 +89,7 @@ def upgrade():
78 89
         depot_file_field = UploadedFile(depot_file_intent, 'tracim')
79 90
         update_query = revision_helper.update() \
80 91
             .where(revision_helper.c.revision_id == file.revision_id) \
81
-            .values(depot_file=depot_file_field) \
82
-            .return_defaults()
92
+            .values(depot_file=depot_file_field)
83 93
         connection.execute(update_query)
84 94
 
85 95
 

+ 9 - 1
tracim/tracim/config/app_cfg.py Voir le fichier

@@ -129,7 +129,7 @@ def start_daemons(manager: DaemonsManager):
129 129
 
130 130
 def configure_depot():
131 131
     """Configure Depot."""
132
-    depot_storage_name = 'tracim'
132
+    depot_storage_name = CFG.get_instance().DEPOT_STORAGE_NAME
133 133
     depot_storage_path = CFG.get_instance().DEPOT_STORAGE_DIR
134 134
     depot_storage_settings = {'depot.storage_path': depot_storage_path}
135 135
     DepotManager.configure(
@@ -219,6 +219,14 @@ class CFG(object):
219 219
                 'ERROR: depot_storage_dir configuration is mandatory. '
220 220
                 'Set it before continuing.'
221 221
             )
222
+        self.DEPOT_STORAGE_NAME = tg.config.get(
223
+            'depot_storage_name',
224
+        )
225
+        if not self.DEPOT_STORAGE_NAME:
226
+            raise Exception(
227
+                'ERROR: depot_storage_name configuration is mandatory. '
228
+                'Set it before continuing.'
229
+            )
222 230
         self.PREVIEW_CACHE_DIR = tg.config.get(
223 231
             'preview_cache_dir',
224 232
         )