1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-03-14 15:22:02 +01:00

Added a settings validator for plugin

This commit is contained in:
m.orban 2016-08-19 09:58:15 +02:00
commit 0e7b5828fa
3 changed files with 22 additions and 31 deletions

Binary file not shown.

View file

@ -793,9 +793,6 @@ with %s" % (custom_method._method_name, custom_method))
#
class SessionHandler(Plugin):
__instance = None
@ -806,3 +803,9 @@ class SessionHandler(Plugin):
def __init__(self, plugin_name):
super(Plugin, self).__init__(plugin_name)
class InterfacePlugin(Plugin):
def __init__(self, plugin_name):
super(Plugin, self).__init__(plugin_name)

View file

@ -238,37 +238,25 @@ def emfield_val(value):
msg = "Following field not found in class %s : %s"
raise SettingsValidationError(msg % value)
return value
def plugin_val(value):
#Late validation hook
@LodelHook('lodel2_dyncode_bootstraped')
def plugin_check(hookname, caller, payload):
from lodel import plugin
for inst in plugin._plugin_instances:
if (!isinstance(value, inst)):
msg = "Following plugin types do not exists in the loader: %s"
raise SettingsValidationError(msg % value)
return value
def plugins_val(value):
spl = value.split('.')
if len(spl) < 1:
msg = "Expected a value in the form PLUGIN.NAME or PLUGIN.VERSION but got : %s"
def plugin_val(value):
if spl = value.split('.')
if len(spl) != 2:
msg = "Expected a value in the form PLUGIN.TYPE but got : %s"
raise SettingsValidationError(msg % value)
value = tuple(spl)
#Late validation hook
@LodelHook('lodel2_dyncode_bootstraped')
def plugin_check(hookname, caller, payload):
from lodel import plugin
pluginnames = { cls.__type.lower():cls for cls in dyncode.dynclasses}
if value[0].lower() not in pluginsnames:
msg = "Following plugin types do not exists in the loader: %s"
raise SettingsValidationError(msg % value[0])
ccls = classnames[value[0].lower()]
if value[1].lower() not in ccls.fieldnames(True):
msg = "Following field not found in class %s : %s"
raise SettingsValidationError(msg % value)
return value
#Late validation hook
@LodelHook('lodel2_dyncode_bootstraped')
def type_check(hookname, caller, payload):
from lodel import plugin
typesname = { cls.__name__.lower():cls for cls in plugin.PLUGINS_TYPE}
if value[1].lower() not in typesname:
msg = "Following plugin type do not exist in plugin list %s : %s"
raise SettingsValidationError(msg % value)
return value
plug_type_val = plugin_val(value)
return plug_type_val
#
# Default validators registration