|
@@ -7,6 +7,8 @@ import socket
|
7
|
7
|
import inspect
|
8
|
8
|
import copy
|
9
|
9
|
|
|
10
|
+from lodel.plugin.hooks import LodelHook
|
|
11
|
+
|
10
|
12
|
## @package lodel.settings.validator Lodel2 settings validators/cast module
|
11
|
13
|
#
|
12
|
14
|
# Validator are registered in the SettingValidator class.
|
|
@@ -31,6 +33,7 @@ class SettingValidator(object):
|
31
|
33
|
def __init__(self, name, none_is_valid = False):
|
32
|
34
|
if name is not None and name not in self._validators:
|
33
|
35
|
raise NameError("No validator named '%s'" % name)
|
|
36
|
+ self.__none_is_valid = none_is_valid
|
34
|
37
|
self.__name = name
|
35
|
38
|
|
36
|
39
|
##@brief Call the validator
|
|
@@ -40,6 +43,8 @@ class SettingValidator(object):
|
40
|
43
|
def __call__(self, value):
|
41
|
44
|
if self.__name is None:
|
42
|
45
|
return value
|
|
46
|
+ if self.__none_is_valid and value is None:
|
|
47
|
+ return None
|
43
|
48
|
try:
|
44
|
49
|
return self._validators[self.__name](value)
|
45
|
50
|
except Exception as e:
|
|
@@ -152,6 +157,8 @@ def file_err_output(value):
|
152
|
157
|
|
153
|
158
|
##@brief Boolean value validator callback
|
154
|
159
|
def boolean_val(value):
|
|
160
|
+ if isinstance(value, bool):
|
|
161
|
+ return value
|
155
|
162
|
if value.strip().lower() == 'true' or value.strip() == '1':
|
156
|
163
|
value = True
|
157
|
164
|
elif value.strip().lower() == 'false' or value.strip() == '0':
|
|
@@ -174,7 +181,7 @@ def loglevel_val(value):
|
174
|
181
|
return value.upper()
|
175
|
182
|
|
176
|
183
|
def path_val(value):
|
177
|
|
- if not os.path.exists(value):
|
|
184
|
+ if value is None or not os.path.exists(value):
|
178
|
185
|
raise SettingsValidationError(
|
179
|
186
|
"path '%s' doesn't exists" % value)
|
180
|
187
|
return value
|
|
@@ -211,6 +218,28 @@ def host_val(value):
|
211
|
218
|
msg = "The value '%s' is not a valid host"
|
212
|
219
|
raise SettingsValidationError(msg % value)
|
213
|
220
|
|
|
221
|
+def emfield_val(value):
|
|
222
|
+ spl = value.split('.')
|
|
223
|
+ if len(spl) != 2:
|
|
224
|
+ msg = "Expected a value in the form CLASSNAME.FIELDNAME but got : %s"
|
|
225
|
+ raise SettingsValidationError(msg % value)
|
|
226
|
+ value = tuple(spl)
|
|
227
|
+ #Late validation hook
|
|
228
|
+ @LodelHook('lodel2_dyncode_bootstraped')
|
|
229
|
+ def emfield_conf_check(hookname, caller, payload):
|
|
230
|
+ from lodel import dyncode
|
|
231
|
+ classnames = { cls.__name__.lower():cls for cls in dyncode.dynclasses}
|
|
232
|
+ if value[0].lower() not in classnames:
|
|
233
|
+ msg = "Following dynamic class do not exists in current EM : %s"
|
|
234
|
+ raise SettingsValidationError(msg % value[0])
|
|
235
|
+ ccls = classnames[value[0].lower()]
|
|
236
|
+ if value[1].lower() not in ccls.fieldnames(True):
|
|
237
|
+ msg = "Following field not found in class %s : %s"
|
|
238
|
+ raise SettingsValidationError(msg % value)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+ return value
|
|
242
|
+
|
214
|
243
|
#
|
215
|
244
|
# Default validators registration
|
216
|
245
|
#
|
|
@@ -270,6 +299,11 @@ SettingValidator.register_validator(
|
270
|
299
|
host_val,
|
271
|
300
|
'host validator')
|
272
|
301
|
|
|
302
|
+SettingValidator.register_validator(
|
|
303
|
+ 'emfield',
|
|
304
|
+ emfield_val,
|
|
305
|
+ 'EmField name validator')
|
|
306
|
+
|
273
|
307
|
SettingValidator.create_list_validator(
|
274
|
308
|
'list',
|
275
|
309
|
SettingValidator('strip'),
|
|
@@ -306,8 +340,6 @@ LODEL2_CONF_SPECS = {
|
306
|
340
|
SettingValidator('list')),
|
307
|
341
|
'sitename': ( 'noname',
|
308
|
342
|
SettingValidator('strip')),
|
309
|
|
- 'lib_path': ( None,
|
310
|
|
- SettingValidator('path')),
|
311
|
343
|
'runtest': ( False,
|
312
|
344
|
SettingValidator('bool')),
|
313
|
345
|
},
|