|
@@ -7,7 +7,6 @@ import socket
|
7
|
7
|
import inspect
|
8
|
8
|
import copy
|
9
|
9
|
|
10
|
|
-
|
11
|
10
|
## @package lodel.settings.validator Lodel2 settings validators/cast module
|
12
|
11
|
#
|
13
|
12
|
# Validator are registered in the SettingValidator class.
|
|
@@ -29,11 +28,15 @@ class SettingValidator(object):
|
29
|
28
|
_description = dict()
|
30
|
29
|
|
31
|
30
|
##@brief Instanciate a validator
|
32
|
|
- def __init__(self, name, none_is_valid = False):
|
|
31
|
+ #@param name str : validator name
|
|
32
|
+ #@param none_is_valid bool : if True None will be validated
|
|
33
|
+ #@param **kwargs : more arguement for the validator
|
|
34
|
+ def __init__(self, name, none_is_valid = False, **kwargs):
|
33
|
35
|
if name is not None and name not in self._validators:
|
34
|
36
|
raise NameError("No validator named '%s'" % name)
|
35
|
37
|
self.__none_is_valid = none_is_valid
|
36
|
38
|
self.__name = name
|
|
39
|
+ self._opt_args = kwargs
|
37
|
40
|
|
38
|
41
|
##@brief Call the validator
|
39
|
42
|
# @param value *
|
|
@@ -45,7 +48,7 @@ class SettingValidator(object):
|
45
|
48
|
if self.__none_is_valid and value is None:
|
46
|
49
|
return None
|
47
|
50
|
try:
|
48
|
|
- return self._validators[self.__name](value)
|
|
51
|
+ return self._validators[self.__name](value, **self._opt_args)
|
49
|
52
|
except Exception as e:
|
50
|
53
|
raise SettingsValidationError(e)
|
51
|
54
|
|
|
@@ -218,6 +221,9 @@ def host_val(value):
|
218
|
221
|
msg = "The value '%s' is not a valid host"
|
219
|
222
|
raise SettingsValidationError(msg % value)
|
220
|
223
|
|
|
224
|
+##@brief Validator for Editorial model component
|
|
225
|
+#
|
|
226
|
+# Designed to validate a conf that indicate a class.field in an EM
|
221
|
227
|
def emfield_val(value):
|
222
|
228
|
from lodel.plugin.hooks import LodelHook
|
223
|
229
|
spl = value.split('.')
|
|
@@ -239,25 +245,29 @@ def emfield_val(value):
|
239
|
245
|
raise SettingsValidationError(msg % value)
|
240
|
246
|
return value
|
241
|
247
|
|
242
|
|
-def plugin_val(value):
|
|
248
|
+##@brief Validator for plugin name & optionnaly type
|
|
249
|
+#
|
|
250
|
+#Able to check that the value is a plugin and if it is of a specific type
|
|
251
|
+def plugin_validator(value, ptype = None):
|
243
|
252
|
from lodel.plugin.hooks import LodelHook
|
244
|
|
- spl = value.split('.')
|
245
|
|
- if len(spl) != 2:
|
246
|
|
- msg = "Expected a value in the form PLUGIN.TYPE but got : %s"
|
247
|
|
- raise SettingsValidationError(msg % value)
|
248
|
|
- value = tuple(spl)
|
249
|
|
- #Late validation hook
|
250
|
253
|
@LodelHook('lodel2_dyncode_bootstraped')
|
251
|
|
- def type_check(hookname, caller, payload):
|
252
|
|
- from lodel import plugin
|
253
|
|
- typesname = { cls.__name__.lower():cls for cls in plugin.PLUGINS_TYPE}
|
254
|
|
- if value[1].lower() not in typesname:
|
255
|
|
- msg = "Following plugin type do not exist in plugin list %s : %s"
|
256
|
|
- raise SettingsValidationError(msg % value)
|
257
|
|
- return value
|
258
|
|
- plug_type_val = plugin_val(value)
|
259
|
|
- return plug_type_val
|
260
|
|
-
|
|
254
|
+ def plugin_type_checker(hookname, caller, payload):
|
|
255
|
+ from lodel.plugin.plugins import Plugin
|
|
256
|
+ from lodel.plugin.exceptions import PluginError
|
|
257
|
+ try:
|
|
258
|
+ plugin = Plugin.get(value)
|
|
259
|
+ except PluginError:
|
|
260
|
+ msg = "No plugin named %s found"
|
|
261
|
+ msg %= value
|
|
262
|
+ raise SettingsValidationError(msg)
|
|
263
|
+ print("HOOKED CHECK : ", plugin._type_conf_name.lower(), ptype.lower())
|
|
264
|
+ if plugin._type_conf_name.lower() != ptype.lower():
|
|
265
|
+ msg = "A plugin of type '%s' was expected but found a plugin \
|
|
266
|
+named '%s' that is a '%s' plugin"
|
|
267
|
+ msg %= (ptype, value, plugin._type_conf_name)
|
|
268
|
+ raise SettingsValidationError(msg)
|
|
269
|
+ return value
|
|
270
|
+
|
261
|
271
|
|
262
|
272
|
#
|
263
|
273
|
# Default validators registration
|
|
@@ -265,8 +275,8 @@ def plugin_val(value):
|
265
|
275
|
|
266
|
276
|
SettingValidator.register_validator(
|
267
|
277
|
'plugin',
|
268
|
|
- plugin_val,
|
269
|
|
- 'plugin validator')
|
|
278
|
+ plugin_validator,
|
|
279
|
+ 'plugin name & type validator')
|
270
|
280
|
|
271
|
281
|
SettingValidator.register_validator(
|
272
|
282
|
'dummy',
|