Browse Source

Untested but written db initialisation function in install/lodel_admin.py

Yann Weber 8 years ago
parent
commit
e3dbdc8e49
3 changed files with 28 additions and 6 deletions
  1. 21
    0
      install/lodel_admin.py
  2. 6
    6
      lodel/leapi/leobject.py
  3. 1
    0
      plugins/mongodb_datasource/__init__.py

+ 21
- 0
install/lodel_admin.py View File

@@ -49,6 +49,9 @@ def refresh_dyncode():
49 49
 def init_all_dbs():
50 50
     import loader
51 51
     import leapi_dyncode as dyncode
52
+    from lodel.settings.utils import SettingsError
53
+    from lodel.leapi.leobject import LeObject
54
+    from lodel.plugin import Plugin
52 55
     ds_cls = dict() # EmClass indexed by rw_datasource
53 56
     for cls in dyncode.dynclasses:
54 57
         ds = cls._datasource_name
@@ -57,6 +60,24 @@ def init_all_dbs():
57 60
         else:
58 61
             ds_cls.append(cls)
59 62
     
63
+    for ds_name in ds_cls:  
64
+        # Fetching datasource plugin name and datasource connection 
65
+        # identifier
66
+        try:
67
+            plugin_name, ds_indentifier = LeObject._get_ds_pugin_name(
68
+                ds_name, False)
69
+        except (NameError, ValueError, RuntimeError):
70
+            raise SettingsError("Datasource configuration error")
71
+        # Fetching datasource connection option
72
+        con_conf=LeObject._get_ds_connection_conf(ds_identifier, plugin_name)
73
+        # Fetching migration handler class from plugin
74
+        plugin_module = Plugin.get(plugin_name).loader_module()
75
+        mh_cls = plugin_module.migration_handler
76
+        #Instanciate the migrationhandler and start db initialisation
77
+        mh = mh_cls(**con_conf)
78
+        mh.init_db(ds_cls[ds_name])
79
+        pass
80
+        
60 81
     #TODO : iter on datasource, fetch ds module and ds option
61 82
     # then instanciate corresponfing MH with given options
62 83
     pass

+ 6
- 6
lodel/leapi/leobject.py View File

@@ -222,7 +222,7 @@ class LeObject(object):
222 222
             raise SettingsError(expt_msg)
223 223
         try:
224 224
             #fetching plugin name
225
-            ds_plugin_name, ds_name = cls._get_ds_plugin_name(ds_name, ro)
225
+            ds_plugin_name, ds_identifier = cls._get_ds_plugin_name(ds_name, ro)
226 226
         except NameError:
227 227
             expt_msg += "Datasource %s is missconfigured, missing identifier."
228 228
             expt_msg %= ds_name
@@ -237,7 +237,7 @@ a read only as a read&write datasource"
237 237
             raise SettingsError(expt_msg)
238 238
         
239 239
         try:
240
-            ds_conf = cls._get_ds_connection_conf(ds_name, ds_plugin_name)
240
+            ds_conf = cls._get_ds_connection_conf(ds_identifier, ds_plugin_name)
241 241
         except NameError as e:
242 242
             expt_msg += str(e)
243 243
             raise SettingsError(expt_msg)
@@ -254,22 +254,22 @@ raised when trying to import Datasource"
254 254
         return datasource_class(**ds_conf)
255 255
 
256 256
     ##@brief Try to fetch a datasource configuration
257
-    #@param ds_name str : datasource name
257
+    #@param ds_identifier str : datasource name
258 258
     #@param ds_plugin_name : datasource plugin name
259 259
     #@return a dict containing datasource initialisation options
260 260
     #@throw NameError if a datasource plugin or instance cannot be found
261 261
     @staticmethod
262
-    def _get_ds_connection_conf(ds_name,ds_plugin_name):
262
+    def _get_ds_connection_conf(ds_identifier,ds_plugin_name):
263 263
         if ds_plugin_name not in Settings.datasource._fields:
264 264
             msg = "Unknown or unconfigured datasource plugin %s"
265 265
             msg %= ds_plugin
266 266
             raise NameError(msg)
267 267
         ds_conf = getattr(Settings.datasource, ds_plugin_name)
268
-        if ds_name not in ds_conf._fields:
268
+        if ds_identifier not in ds_conf._fields:
269 269
             msg = "Unknown or unconfigured datasource instance %s"
270 270
             msg %= ds_identifier
271 271
             raise NameError(msg)
272
-        ds_conf = getattr(ds_conf, ds_name)
272
+        ds_conf = getattr(ds_conf, ds_identifier)
273 273
         return {k: getattr(ds_conf,k) for k in ds_conf._fields }
274 274
 
275 275
     ##@brief fetch datasource plugin name

+ 1
- 0
plugins/mongodb_datasource/__init__.py View File

@@ -1,6 +1,7 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 __loader__ = "main.py"
3 3
 __confspec__ = "confspec.py"
4
+
4 5
 __author__ = "Lodel2 dev team"
5 6
 __fullname__ = "MongoDB plugin"
6 7
 

Loading…
Cancel
Save