Browse Source

Documentation on datasources plugins + confspec updates in validator.py

+ a new validator named 'string', it tries to cast the conf value using str()
Yann Weber 8 years ago
parent
commit
6fb04a69fb

+ 15
- 0
lodel/settings/validator.py View File

@@ -183,6 +183,12 @@ def none_val(value):
183 183
         return None
184 184
     raise SettingsValidationError("This settings cannot be set in configuration file")
185 185
 
186
+def str_val(value):
187
+    try:
188
+        str(value)
189
+    except Exception as e:
190
+        raise SettingsValidationError("Not able to convert value to string : " + str(e))
191
+
186 192
 #
187 193
 #   Default validators registration
188 194
 #
@@ -197,6 +203,11 @@ SettingValidator.register_validator(
197 203
                                         none_val,
198 204
                                         'Validate None')
199 205
 
206
+SettingValidator.register_validator(
207
+                                        'string',
208
+                                        str_val,
209
+                                        'Validate string values')
210
+
200 211
 SettingValidator.register_validator(
201 212
                                         'strip',
202 213
                                         str.strip,
@@ -294,5 +305,9 @@ LODEL2_CONF_SPECS = {
294 305
                     SettingValidator('list')),
295 306
         'editormode': ( False,
296 307
                         SettingValidator('bool')),
308
+    },
309
+    'lodel2.datasources.*': {
310
+            'identifier': ( None,
311
+                            SettingValidator('string'))
297 312
     }
298 313
 }

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


+ 81
- 0
plugins/dummy_datasource/confspec.py View File

@@ -0,0 +1,81 @@
1
+#-*- coding: utf-8 -*-
2
+
3
+from lodel.settings.validator import SettingValidator
4
+
5
+CONFSPEC = {}
6
+
7
+##@page lodel2_datasources Lodel2 datasources
8
+#
9
+#@par lodel2_datasources_intro Intro
10
+# A single lodel2 website can interact with multiple datasources. This page
11
+# aims to describe configuration & organisation of datasources in lodel2.
12
+# Each object is attached to a datasource. This association is done in the
13
+# editorial model, the datasource is identified by a name.
14
+#
15
+#@par Datasources declaration
16
+# To define a datasource you have to write something like this in confs file :
17
+#<pre>
18
+#[lodel2.datasources.DATASOURCE_NAME]
19
+#identifier = DATASOURCE_FAMILY.SOURCE_NAME
20
+#</pre>
21
+# See below for DATASOURCE_FAMILY & SOURCE_NAME
22
+#
23
+#@par Datasources plugins
24
+# Each datasource family is a plugin. For example mysql or a mongodb plugins.
25
+# Here is the CONFSPEC variable templates for datasources plugins
26
+#<pre>
27
+#CONFSPEC = {
28
+#                'lodel2.datasource.example.*' : {
29
+#                    'conf1' : VALIDATOR_OPTS,
30
+#                    'conf2' : VALIDATOR_OPTS,
31
+#                    ...
32
+#                }
33
+#}
34
+#</pre>
35
+#MySQL example
36
+#<pre>
37
+#CONFSPEC = {
38
+#                'lodel2.datasource.mysql.*' : {
39
+#                    'host': (   'localhost',
40
+#                                SettingValidator('host')),
41
+#                    'db_name': (    'lodel',
42
+#                                    SettingValidator('string')),
43
+#                    'username': (   None,
44
+#                                    SettingValidator('string')),
45
+#                    'password': (   None,
46
+#                                    SettingValidator('string')),
47
+#                }
48
+#}
49
+#</pre>
50
+#
51
+#@par Configuration example
52
+#<pre>
53
+# [lodel2.datasources.main]
54
+# identifier = mysql.Core
55
+# [lodel2.datasources.revues_write]
56
+# identifier = mysql.Revues
57
+# [lodel2.datasources.revues_read]
58
+# identifier = mysql.Revues
59
+# [lodel2.datasources.annuaire_persons]
60
+# identifier = persons_web_api.example
61
+# ;
62
+# ; Then, in the editorial model you are able to use "main", "revues_write", 
63
+# ; etc as datasource
64
+# ;
65
+# ; Here comes the datasources declarations
66
+# [lodel2.datasource.mysql.Core]
67
+# host = db.core.labocleo.org
68
+# db_name = core
69
+# username = foo
70
+# password = bar
71
+# ;
72
+# [lodel2.datasource.mysql.Revues]
73
+# host = revues.org
74
+# db_name = RO
75
+# username = foo
76
+# password = bar
77
+# ;
78
+# [lodel2.datasource.persons_web_api.example]
79
+# host = foo.bar
80
+# username = cleo
81
+#</pre>

Loading…
Cancel
Save