소스 검색

Added inheritance class SessionHandler (Plugin is the base-class

m.orban 7 년 전
부모
커밋
81e732a6af
2개의 변경된 파일57개의 추가작업 그리고 7개의 파일을 삭제
  1. 21
    5
      lodel/plugin/plugins.py
  2. 36
    2
      lodel/settings/validator.py

+ 21
- 5
lodel/plugin/plugins.py 파일 보기

@@ -41,8 +41,8 @@ DEFAULT_PLUGINS_PATH_LIST = ['./plugins']
41 41
 MANDATORY_VARNAMES = [PLUGIN_NAME_VARNAME, LOADER_FILENAME_VARNAME, 
42 42
     PLUGIN_VERSION_VARNAME]
43 43
 
44
-PLUGIN_DEFAULT_TYPE = 'default'
45
-PLUGINS_TYPES = [PLUGIN_DEFAULT_TYPE, 'datasource', 'session_handler', 'ui']
44
+EXTENSIONS = 'default'
45
+PLUGINS_TYPES = [EXTENSIONS, 'datasource', 'session_handler', 'ui']
46 46
 
47 47
 
48 48
 ##@brief Describe and handle version numbers
@@ -248,7 +248,7 @@ init file. Malformed plugin"
248 248
         try:
249 249
             self.__type = getattr(self.module, PLUGIN_TYPE_VARNAME)
250 250
         except AttributeError:
251
-            self.__type = PLUGIN_DEFAULT_TYPE
251
+            self.__type = EXTENSIONS
252 252
         self.__type = str(self.__type).lower()
253 253
         if self.__type not in PLUGINS_TYPES:
254 254
             raise PluginError("Unknown plugin type '%s'" % self.__type)
@@ -296,7 +296,7 @@ name differ from the one found in plugin's init file"
296 296
         filename = os.path.join(self.path, filename)
297 297
         loader = SourceFileLoader(module_name, filename)
298 298
         return loader.load_module()
299
-    
299
+   
300 300
     ##@brief Check dependencies of plugin
301 301
     #@return A list of plugin name to be loaded before
302 302
     def check_deps(self):
@@ -419,7 +419,8 @@ name differ from the one found in plugin's init file"
419 419
         from lodel.plugin.hooks import LodelHook
420 420
         LodelHook.call_hook(
421 421
             "lodel2_plugins_loaded", cls, cls._plugin_instances)
422
-    
422
+   
423
+
423 424
     ##@return a copy of __confspecs attr
424 425
     @property
425 426
     def confspecs(self):
@@ -785,3 +786,18 @@ with %s" % (custom_method._method_name, custom_method))
785 786
 # - an _activate() method that returns True if the plugin can be activated (
786 787
 # optionnal)
787 788
 #
789
+
790
+
791
+
792
+
793
+
794
+class SessionHandler(Plugin):
795
+    __instance = None
796
+
797
+    def __new__(cls):
798
+        if cls.__instance == None:
799
+            cls.instance == object.__new__(cls)
800
+        return cls.__instance
801
+        
802
+    def __init__(self, plugin_name):
803
+        super(Plugin, self).__init__(plugin_name)

+ 36
- 2
lodel/settings/validator.py 파일 보기

@@ -237,14 +237,48 @@ def emfield_val(value):
237 237
         if value[1].lower() not in ccls.fieldnames(True):
238 238
             msg = "Following field not found in class %s : %s"
239 239
             raise SettingsValidationError(msg % value)
240
-            
241
-            
242 240
     return value
243 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
+
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"
257
+        raise SettingsValidationError(msg % value)
258
+    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
272
+
244 273
 #
245 274
 #   Default validators registration
246 275
 #
247 276
 
277
+SettingValidator.register_validator(
278
+    'plugin',
279
+    plugin_val,
280
+    'plugin validator')
281
+
248 282
 SettingValidator.register_validator(
249 283
     'dummy',
250 284
     lambda value:value,

Loading…
취소
저장