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
 def init_all_dbs():
49
 def init_all_dbs():
50
     import loader
50
     import loader
51
     import leapi_dyncode as dyncode
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
     ds_cls = dict() # EmClass indexed by rw_datasource
55
     ds_cls = dict() # EmClass indexed by rw_datasource
53
     for cls in dyncode.dynclasses:
56
     for cls in dyncode.dynclasses:
54
         ds = cls._datasource_name
57
         ds = cls._datasource_name
57
         else:
60
         else:
58
             ds_cls.append(cls)
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
     #TODO : iter on datasource, fetch ds module and ds option
81
     #TODO : iter on datasource, fetch ds module and ds option
61
     # then instanciate corresponfing MH with given options
82
     # then instanciate corresponfing MH with given options
62
     pass
83
     pass

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

222
             raise SettingsError(expt_msg)
222
             raise SettingsError(expt_msg)
223
         try:
223
         try:
224
             #fetching plugin name
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
         except NameError:
226
         except NameError:
227
             expt_msg += "Datasource %s is missconfigured, missing identifier."
227
             expt_msg += "Datasource %s is missconfigured, missing identifier."
228
             expt_msg %= ds_name
228
             expt_msg %= ds_name
237
             raise SettingsError(expt_msg)
237
             raise SettingsError(expt_msg)
238
         
238
         
239
         try:
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
         except NameError as e:
241
         except NameError as e:
242
             expt_msg += str(e)
242
             expt_msg += str(e)
243
             raise SettingsError(expt_msg)
243
             raise SettingsError(expt_msg)
254
         return datasource_class(**ds_conf)
254
         return datasource_class(**ds_conf)
255
 
255
 
256
     ##@brief Try to fetch a datasource configuration
256
     ##@brief Try to fetch a datasource configuration
257
-    #@param ds_name str : datasource name
257
+    #@param ds_identifier str : datasource name
258
     #@param ds_plugin_name : datasource plugin name
258
     #@param ds_plugin_name : datasource plugin name
259
     #@return a dict containing datasource initialisation options
259
     #@return a dict containing datasource initialisation options
260
     #@throw NameError if a datasource plugin or instance cannot be found
260
     #@throw NameError if a datasource plugin or instance cannot be found
261
     @staticmethod
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
         if ds_plugin_name not in Settings.datasource._fields:
263
         if ds_plugin_name not in Settings.datasource._fields:
264
             msg = "Unknown or unconfigured datasource plugin %s"
264
             msg = "Unknown or unconfigured datasource plugin %s"
265
             msg %= ds_plugin
265
             msg %= ds_plugin
266
             raise NameError(msg)
266
             raise NameError(msg)
267
         ds_conf = getattr(Settings.datasource, ds_plugin_name)
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
             msg = "Unknown or unconfigured datasource instance %s"
269
             msg = "Unknown or unconfigured datasource instance %s"
270
             msg %= ds_identifier
270
             msg %= ds_identifier
271
             raise NameError(msg)
271
             raise NameError(msg)
272
-        ds_conf = getattr(ds_conf, ds_name)
272
+        ds_conf = getattr(ds_conf, ds_identifier)
273
         return {k: getattr(ds_conf,k) for k in ds_conf._fields }
273
         return {k: getattr(ds_conf,k) for k in ds_conf._fields }
274
 
274
 
275
     ##@brief fetch datasource plugin name
275
     ##@brief fetch datasource plugin name

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

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

Loading…
Cancel
Save