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,6 +373,11 @@ name differ from the one found in plugin's init file"
373 373
     #@throw AttributeError if varname not found
374 374
     #@throw ImportError if the file fails to be imported
375 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 381
     def _import_from_init_var(self, varname):
377 382
         # Read varname
378 383
         try:
@@ -391,9 +396,14 @@ name differ from the one found in plugin's init file"
391 396
                 fname = filename,
392 397
                 name = self.name)
393 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 404
         #extract module name from filename
395 405
         base_mod = '.'.join(filename.split('.')[:-1])
396
-        module_name = self.module.__name__+"."+base_mod
406
+        module_name = self_modname+"."+base_mod
397 407
         return importlib.import_module(module_name)
398 408
    
399 409
     ##@brief Check dependencies of plugin
@@ -701,7 +711,6 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
701 711
                 #dropped
702 712
                 pass
703 713
         result = {'path_list': paths, 'plugins': result}
704
-        print("DEUG ",result['plugins'])
705 714
         #Writing to cache
706 715
         if not no_cache:
707 716
             with open(DISCOVER_CACHE_FILENAME, 'w+') as pdcache:
@@ -806,7 +815,8 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
806 815
     ##@brief Import init file from a plugin path
807 816
     #@param path str : Directory path
808 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 820
     @classmethod
811 821
     def import_init(cls, path):
812 822
         cls._mod_cnt += 1 # in order to ensure module name unicity

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

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

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

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

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

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

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

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

Loading…
Cancel
Save