Browse Source

Progress in datasource as plugin implementation

Yann Weber 8 years ago
parent
commit
f8e8750eec

+ 5
- 0
install/conf.d/datasources.ini View File

@@ -0,0 +1,5 @@
1
+[lodel2.datasources.main]
2
+identifier = dummy.example
3
+
4
+[lodel2.datasource.dummy.example]
5
+dummy =

+ 1
- 1
install/conf.d/lodel2.ini View File

@@ -2,7 +2,7 @@
2 2
 debug = False
3 3
 sitename = noname
4 4
 plugins_path = /foo/plugins
5
-plugins = dummy, webui
5
+plugins = dummy, webui, datasources, dummy_datasource
6 6
 
7 7
 [lodel2.logging.stderr]
8 8
 level = DEBUG

+ 4
- 1
install/loader.py View File

@@ -22,12 +22,15 @@ from lodel.settings.settings import Settings as settings
22 22
 settings('conf.d')
23 23
 from lodel.settings import Settings
24 24
 
25
+
25 26
 #Load plugins
26 27
 from lodel.plugin import Plugins
27 28
 Plugins.bootstrap()
28 29
 
30
+from lodel.plugin import LodelHook
31
+LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
32
+
29 33
 if __name__ == '__main__':
30
-    from lodel.plugin import LodelHook
31 34
     LodelHook.call_hook('lodel2_loader_main', '__main__', None)
32 35
     #Run interative python
33 36
     import code

+ 1
- 5
lodel/settings/validator.py View File

@@ -185,7 +185,7 @@ def none_val(value):
185 185
 
186 186
 def str_val(value):
187 187
     try:
188
-        str(value)
188
+        return str(value)
189 189
     except Exception as e:
190 190
         raise SettingsValidationError("Not able to convert value to string : " + str(e))
191 191
 
@@ -306,8 +306,4 @@ LODEL2_CONF_SPECS = {
306 306
         'editormode': ( False,
307 307
                         SettingValidator('bool')),
308 308
     },
309
-    'lodel2.datasources.*': {
310
-            'identifier': ( None,
311
-                            SettingValidator('string'))
312
-    }
313 309
 }

+ 0
- 0
plugins/datasources/__init__.py View File


+ 8
- 0
plugins/datasources/confspec.py View File

@@ -0,0 +1,8 @@
1
+#-*- coding: utf-8 -*-
2
+
3
+from lodel.settings.validator import SettingValidator
4
+
5
+CONFSPEC = {
6
+                'lodel2.datasources.*': {
7
+                        'identifier': ( None,
8
+                                        SettingValidator('string'))}}

+ 33
- 0
plugins/datasources/main.py View File

@@ -0,0 +1,33 @@
1
+#-*- coding: utf-8 -*-
2
+
3
+from lodel.plugin import LodelHook
4
+from lodel.settings import Settings
5
+from lodel import logger
6
+
7
+
8
+##@brief Bootstrap hook to check datasources configuration
9
+@LodelHook('lodel2_bootstraped')
10
+def datasources_bootstrap_callaback(hook_name, caller, payload):
11
+    for ds_name in Settings.datasources._fields:
12
+        ds_conf = getattr(Settings.datasources, ds_name)
13
+        identifier = getattr(ds_conf, 'identifier')
14
+
15
+        # Now we are trying to fetch the datasource given the identifier
16
+        ds_family_name, ds_name = identifier.split('.',1)
17
+        try:
18
+            ds_fam = getattr(Settings.datasource, ds_family_name)
19
+        except AttributeError:
20
+            msg = "No datasource family named '%s' found"
21
+            msg %= ds_family_name
22
+            raise NameError(msg)
23
+        try:
24
+            ds = getattr(ds_fam, ds_name)
25
+        except AttributeError:
26
+            msg = "No datasource configured for identifier '%s' found"
27
+            msg %= identifier
28
+            raise NameError(msg)
29
+
30
+
31
+        log_msg = "Found a datasource named '%s' identified by '%s'"
32
+        log_msg %= (ds_name, identifier)
33
+        logger.debug(log_msg)

+ 5
- 1
plugins/dummy_datasource/confspec.py View File

@@ -2,7 +2,11 @@
2 2
 
3 3
 from lodel.settings.validator import SettingValidator
4 4
 
5
-CONFSPEC = {}
5
+CONFSPEC = {
6
+    'lodel2.datasource.dummy.*' : {
7
+        'dummy': (  None,
8
+                    SettingValidator('dummy'))}
9
+}
6 10
 
7 11
 ##@page lodel2_datasources Lodel2 datasources
8 12
 #

+ 0
- 0
plugins/dummy_datasource/main.py View File


+ 6
- 1
tests/tests_conf.d/lodel2.ini View File

@@ -2,7 +2,7 @@
2 2
 debug = False
3 3
 sitename = noname
4 4
 plugins_path = plugins
5
-plugins = dummy, webui
5
+plugins = dummy, webui, dummy_datasource, datasources
6 6
 
7 7
 [lodel2.logging.stderr]
8 8
 level = DEBUG
@@ -15,3 +15,8 @@ emfile = editorial_model.pickle
15 15
 dyncode = leapi_dyncode.py
16 16
 editormode = True
17 17
 
18
+[lodel2.datasources.main]
19
+identifier = dummy.example
20
+
21
+[lodel2.datasource.dummy.example]
22
+dummy =

Loading…
Cancel
Save