Selaa lähdekoodia

Added a settings validator for plugin

m.orban 7 vuotta sitten
vanhempi
commit
0e7b5828fa
3 muutettua tiedostoa jossa 22 lisäystä ja 31 poistoa
  1. BIN
      examples/em_test.pickle
  2. 6
    3
      lodel/plugin/plugins.py
  3. 16
    28
      lodel/settings/validator.py

BIN
examples/em_test.pickle Näytä tiedosto


+ 6
- 3
lodel/plugin/plugins.py Näytä tiedosto

@@ -793,9 +793,6 @@ with %s" % (custom_method._method_name, custom_method))
793 793
 #
794 794
 
795 795
 
796
-
797
-
798
-
799 796
 class SessionHandler(Plugin):
800 797
     __instance = None
801 798
 
@@ -806,3 +803,9 @@ class SessionHandler(Plugin):
806 803
         
807 804
     def __init__(self, plugin_name):
808 805
         super(Plugin, self).__init__(plugin_name)
806
+
807
+class InterfacePlugin(Plugin):
808
+    def __init__(self, plugin_name):
809
+        super(Plugin, self).__init__(plugin_name)
810
+
811
+        

+ 16
- 28
lodel/settings/validator.py Näytä tiedosto

@@ -238,37 +238,25 @@ def emfield_val(value):
238 238
             msg = "Following field not found in class %s : %s"
239 239
             raise SettingsValidationError(msg % value)
240 240
     return value
241
-        
242
-def plugin_val(value):
243
-    #Late validation hook
244
-    @LodelHook('lodel2_dyncode_bootstraped')
245
-    def plugin_check(hookname, caller, payload):
246
-        from lodel import plugin
247
-        for inst in plugin._plugin_instances:
248
-            if (!isinstance(value, inst)):
249
-                msg = "Following plugin types do not exists in the loader: %s"
250
-                raise SettingsValidationError(msg % value)
251
-    return value
252 241
 
253
-def plugins_val(value):
254
-    spl = value.split('.')
255
-    if len(spl) < 1:
256
-        msg = "Expected a value in the form PLUGIN.NAME or PLUGIN.VERSION but got : %s"
242
+def plugin_val(value):
243
+    if spl = value.split('.')
244
+    if len(spl) != 2:
245
+        msg = "Expected a value in the form PLUGIN.TYPE but got : %s"
257 246
         raise SettingsValidationError(msg % value)
258 247
     value = tuple(spl)
259
-    #Late validation hook
260
-    @LodelHook('lodel2_dyncode_bootstraped')
261
-    def plugin_check(hookname, caller, payload):
262
-        from lodel import plugin
263
-        pluginnames = { cls.__type.lower():cls for cls in dyncode.dynclasses}
264
-        if value[0].lower() not in pluginsnames:
265
-            msg = "Following plugin types do not exists in the loader: %s"
266
-            raise SettingsValidationError(msg % value[0])
267
-        ccls = classnames[value[0].lower()]
268
-        if value[1].lower() not in ccls.fieldnames(True):
269
-            msg = "Following field not found in class %s : %s"
270
-            raise SettingsValidationError(msg % value)
271
-    return value
248
+        #Late validation hook
249
+        @LodelHook('lodel2_dyncode_bootstraped')
250
+        def type_check(hookname, caller, payload):
251
+            from lodel import plugin
252
+            typesname = { cls.__name__.lower():cls for cls in plugin.PLUGINS_TYPE}
253
+            if value[1].lower() not in typesname:
254
+                msg = "Following plugin type do not exist in plugin list %s : %s"
255
+                raise SettingsValidationError(msg % value)
256
+            return value
257
+    plug_type_val = plugin_val(value)
258
+    return plug_type_val
259
+
272 260
 
273 261
 #
274 262
 #   Default validators registration

Loading…
Peruuta
Tallenna