Browse Source

Bugfixes in lodel_admin init_db action

Yann Weber 7 years ago
parent
commit
a82a75dfc6
2 changed files with 24 additions and 32 deletions
  1. 6
    30
      install/lodel_admin.py
  2. 18
    2
      lodel/plugin/datasource_plugin.py

+ 6
- 30
install/lodel_admin.py View File

@@ -65,6 +65,7 @@ def init_all_dbs():
65 65
     import loader
66 66
     loader.start()
67 67
     import leapi_dyncode as dyncode
68
+    from lodel.plugin.datasource_plugin import DatasourcePlugin
68 69
     from lodel.settings.utils import SettingsError
69 70
     from lodel.leapi.leobject import LeObject
70 71
     from lodel.plugin import Plugin
@@ -78,36 +79,11 @@ def init_all_dbs():
78 79
         else:
79 80
             ds_cls[ds].append(cls)
80 81
     
81
-    for ds_name in ds_cls:  
82
-        # Fetching datasource plugin name and datasource connection 
83
-        # identifier
84
-        try:
85
-            plugin_name, ds_identifier = LeObject._get_ds_plugin_name(
86
-                ds_name, False)
87
-        except (NameError, ValueError, RuntimeError):
88
-            raise SettingsError("Datasource configuration error")
89
-        # Fetching datasource connection option
90
-        con_conf=LeObject._get_ds_connection_conf(ds_identifier, plugin_name)
91
-        # Fetching migration handler class from plugin
92
-        plugin_module = Plugin.get(plugin_name).loader_module()
93
-        try:
94
-            mh_cls = plugin_module.migration_handler_class()
95
-        except NameError as e:
96
-            raise RuntimeError("Malformed plugin '%s'. Missing \
97
-migration_handler_class() function in loader file" % ds_name)
98
-        #Instanciate the migrationhandler and start db initialisation
99
-        if con_conf['read_only'] is True:
100
-            raise SettingsError("Trying to instanciate a migration handler \
101
-with a read only datasource")
102
-        try:
103
-            if 'read_only' in con_conf:
104
-                del(con_conf['read_only'])
105
-            mh = mh_cls(**con_conf)
106
-        except Exception as e:
107
-            msg = "Migration failed for datasource %s(%s.%s) at migration \
108
-handler instanciation : %s"
109
-            msg %= (ds_name, plugin_name, ds_identifier, e)
110
-            raise RuntimeError(msg)
82
+    for ds_name in ds_cls:
83
+        mh = DatasourcePlugin.init_migration_handler(ds_name)
84
+        #Retrieve plugin_name & ds_identifier for logging purpose
85
+        plugin_name, ds_identifier = DatasourcePlugin.plugin_name(
86
+            ds_name, False)
111 87
         try:
112 88
             mh.init_db(ds_cls[ds_name])
113 89
         except Exception as e:

+ 18
- 2
lodel/plugin/datasource_plugin.py View File

@@ -27,7 +27,7 @@ class DatasourcePlugin(Plugin):
27 27
             self.__datasource_cls = self.loader_module().Datasource
28 28
         return self.__datasource_cls
29 29
 
30
-    def migration_handler(self):
30
+    def migration_handler_cls(self):
31 31
         return self.loader_module().migration_handler_class()
32 32
 
33 33
     ##@brief Return an initialized Datasource instance
@@ -42,6 +42,22 @@ class DatasourcePlugin(Plugin):
42 42
         ds_conf = cls._get_ds_connection_conf(ds_identifier, plugin_name)
43 43
         ds_cls = cls.get_datasource(plugin_name)
44 44
         return ds_cls(**ds_conf)
45
+    
46
+    ##@brief Return an initialized MigrationHandler instance
47
+    #@param ds_name str : The datasource name
48
+    #@return A properly initialized MigrationHandler instance
49
+    @classmethod
50
+    def init_migration_handler(cls, ds_name):
51
+        plugin_name, ds_identifier = cls.plugin_name(ds_name, False)
52
+        ds_conf = cls._get_ds_connection_conf(ds_identifier, plugin_name)
53
+        mh_cls = cls.get_migration_handler(plugin_name)
54
+        if 'read_only' in ds_conf:
55
+            if ds_conf['read_only']:
56
+                raise PluginError("A read only datasource was given to \
57
+migration handler !!!")
58
+            del(ds_conf['read_only'])
59
+        return mh_cls(**ds_conf)
60
+
45 61
 
46 62
     ##@brief Given a datasource name returns a DatasourcePlugin name
47 63
     #@param ds_name str : datasource name
@@ -125,5 +141,5 @@ but %s is a %s" % (ds_name, pinstance.__class__.__name__))
125 141
 
126 142
     @classmethod
127 143
     def get_migration_handler(cls, ds_plugin_name):
128
-        return cls.get(ds_plugin_name).migration_handler_class()
144
+        return cls.get(ds_plugin_name).migration_handler_cls()
129 145
  

Loading…
Cancel
Save