Browse Source

Changes & bugfix in lodel.plugin.plugins

There were manual import through importlib, we have to replace them with LodelContext calls.
Actually the plugins module is in a dirty state....
Yann Weber 8 years ago
parent
commit
2be79e50f0

+ 13
- 3
lodel/plugin/plugins.py View File

373
     #@throw AttributeError if varname not found
373
     #@throw AttributeError if varname not found
374
     #@throw ImportError if the file fails to be imported
374
     #@throw ImportError if the file fails to be imported
375
     #@throw PluginError if the filename was not valid
375
     #@throw PluginError if the filename was not valid
376
+    #@todo Some strange things append :
377
+    #when loading modules in test self.module.__name__ does not contains
378
+    #the package... but in prod cases the self.module.__name__ is 
379
+    #the module fullname... Just a reminder note to explain the dirty
380
+    #if on self_modname
376
     def _import_from_init_var(self, varname):
381
     def _import_from_init_var(self, varname):
377
         # Read varname
382
         # Read varname
378
         try:
383
         try:
391
                 fname = filename,
396
                 fname = filename,
392
                 name = self.name)
397
                 name = self.name)
393
             raise PluginError(msg)
398
             raise PluginError(msg)
399
+        #See the todo
400
+        if len(self.module.__name__.split('.')) == 1:
401
+            self_modname = self.module.__package__
402
+        else:
403
+            self_modname = self.module.__name__
394
         #extract module name from filename
404
         #extract module name from filename
395
         base_mod = '.'.join(filename.split('.')[:-1])
405
         base_mod = '.'.join(filename.split('.')[:-1])
396
-        module_name = self.module.__name__+"."+base_mod
406
+        module_name = self_modname+"."+base_mod
397
         return importlib.import_module(module_name)
407
         return importlib.import_module(module_name)
398
    
408
    
399
     ##@brief Check dependencies of plugin
409
     ##@brief Check dependencies of plugin
701
                 #dropped
711
                 #dropped
702
                 pass
712
                 pass
703
         result = {'path_list': paths, 'plugins': result}
713
         result = {'path_list': paths, 'plugins': result}
704
-        print("DEUG ",result['plugins'])
705
         #Writing to cache
714
         #Writing to cache
706
         if not no_cache:
715
         if not no_cache:
707
             with open(DISCOVER_CACHE_FILENAME, 'w+') as pdcache:
716
             with open(DISCOVER_CACHE_FILENAME, 'w+') as pdcache:
806
     ##@brief Import init file from a plugin path
815
     ##@brief Import init file from a plugin path
807
     #@param path str : Directory path
816
     #@param path str : Directory path
808
     #@return a tuple (init_module, module_name)
817
     #@return a tuple (init_module, module_name)
809
-    #@todo very dirty, clean it
818
+    #@todo replace by LodelContext usage !!! (not mandatory, this fun
819
+    #is only used in plugin discover method)
810
     @classmethod
820
     @classmethod
811
     def import_init(cls, path):
821
     def import_init(cls, path):
812
         cls._mod_cnt += 1 # in order to ensure module name unicity
822
         cls._mod_cnt += 1 # in order to ensure module name unicity

+ 1
- 1
lodel/plugins/dummy/__init__.py View File

8
 __confspec__ = "confspec.py"
8
 __confspec__ = "confspec.py"
9
 __author__ = "Lodel2 dev team"
9
 __author__ = "Lodel2 dev team"
10
 __fullname__ = "Dummy plugin"
10
 __fullname__ = "Dummy plugin"
11
-__name__ = 'yweber.dummy'
11
+__name__ = 'dummy'
12
 __plugin_type__ = 'extension'
12
 __plugin_type__ = 'extension'
13
 
13
 
14
 
14
 

+ 1
- 1
lodel/plugins/ram_sessions/__init__.py View File

2
 LodelContext.expose_modules(globals(), {
2
 LodelContext.expose_modules(globals(), {
3
     'lodel.settings.validator': ['SettingValidator']})
3
     'lodel.settings.validator': ['SettingValidator']})
4
 
4
 
5
-__plugin_name__ = 'ram_session'
5
+__plugin_name__ = 'ram_sessions'
6
 __version__ = [0,0,1]
6
 __version__ = [0,0,1]
7
 __plugin_type__ = 'session_handler'
7
 __plugin_type__ = 'session_handler'
8
 __loader__ = 'main.py'
8
 __loader__ = 'main.py'

+ 1
- 1
tests/plugin/test_plugin.py View File

39
     @classmethod
39
     @classmethod
40
     def setUpClass(cls):
40
     def setUpClass(cls):
41
         Plugin.clear()
41
         Plugin.clear()
42
-        Plugin.start(['dummy', 'dummy_datasource', 'webui', 'ram_session'])
42
+        Plugin.start(['dummy', 'dummy_datasource', 'webui', 'ram_sessions'])
43
 
43
 
44
     @classmethod
44
     @classmethod
45
     def tearDownClass(cls):
45
     def tearDownClass(cls):

+ 1
- 1
tests/tests_conf.d/lodel2.ini View File

4
 runtest=True
4
 runtest=True
5
 extensions = dummy
5
 extensions = dummy
6
 datasource_connectors = dummy_datasource
6
 datasource_connectors = dummy_datasource
7
-session_handler = ram_session
7
+session_handler = ram_sessions
8
 
8
 
9
 [lodel2.logging.stderr]
9
 [lodel2.logging.stderr]
10
 level = Error
10
 level = Error

Loading…
Cancel
Save