|
@@ -216,6 +216,13 @@ class MetaPlugType(type):
|
216
|
216
|
if ptype_name not in cls._all_ptypes:
|
217
|
217
|
raise PluginError("Unknown plugin type '%s'" % ptype_name)
|
218
|
218
|
return cls._all_ptypes[ptype_name]
|
|
219
|
+
|
|
220
|
+ ##@brief Call the clear classmethod on each child classes
|
|
221
|
+ @classmethod
|
|
222
|
+ def clear_cls(cls):
|
|
223
|
+ for pcls in cls._all_ptypes.values():
|
|
224
|
+ pcls.clear_cls()
|
|
225
|
+
|
219
|
226
|
|
220
|
227
|
##@brief Handle plugins
|
221
|
228
|
#@ingroup lodel2_plugins
|
|
@@ -254,6 +261,12 @@ class Plugin(object, metaclass=MetaPlugType):
|
254
|
261
|
#None in abstract classes and implemented by child classes
|
255
|
262
|
_type_conf_name = None
|
256
|
263
|
|
|
264
|
+ ##@brief Stores virtual modules uniq key
|
|
265
|
+ #@note When testing if a dir contains a plugin, if we reimport the __init__
|
|
266
|
+ #in a module with the same name, all non existing value (plugin_type for
|
|
267
|
+ #example) are replaced by previous plugin values
|
|
268
|
+ _mod_cnt = 0
|
|
269
|
+
|
257
|
270
|
##@brief Plugin class constructor
|
258
|
271
|
#
|
259
|
272
|
# Called by setting in early stage of lodel2 boot sequence using classmethod
|
|
@@ -656,6 +669,12 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
|
656
|
669
|
cls._plugin_instances = dict()
|
657
|
670
|
if cls._load_called != []:
|
658
|
671
|
cls._load_called = []
|
|
672
|
+ MetaPlugType.clear_cls()
|
|
673
|
+
|
|
674
|
+ ##@brief Designed to be implemented by child classes
|
|
675
|
+ @classmethod
|
|
676
|
+ def clear_cls(cls):
|
|
677
|
+ pass
|
659
|
678
|
|
660
|
679
|
##@brief Reccursively walk throught paths to find plugin, then stores
|
661
|
680
|
#found plugin in a file...
|
|
@@ -684,6 +703,7 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
|
684
|
703
|
#dropped
|
685
|
704
|
pass
|
686
|
705
|
result = {'path_list': paths, 'plugins': result}
|
|
706
|
+ print("DEUG ",result['plugins'])
|
687
|
707
|
#Writing to cache
|
688
|
708
|
if not no_cache:
|
689
|
709
|
with open(DISCOVER_CACHE_FILENAME, 'w+') as pdcache:
|
|
@@ -789,11 +809,12 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
|
789
|
809
|
#@param path str : Directory path
|
790
|
810
|
#@return a tuple (init_module, module_name)
|
791
|
811
|
@classmethod
|
792
|
|
- def import_init(self, path):
|
|
812
|
+ def import_init(cls, path):
|
|
813
|
+ cls._mod_cnt += 1 # in order to ensure module name unicity
|
793
|
814
|
init_source = os.path.join(path, INIT_FILENAME)
|
794
|
|
- temp_module = '%s.%s.%s' % (
|
|
815
|
+ temp_module = '%s.%s.%s%d' % (
|
795
|
816
|
VIRTUAL_TEMP_PACKAGE_NAME, os.path.basename(os.path.dirname(path)),
|
796
|
|
- 'test_init')
|
|
817
|
+ 'test_init', cls._mod_cnt)
|
797
|
818
|
try:
|
798
|
819
|
loader = SourceFileLoader(temp_module, init_source)
|
799
|
820
|
except (ImportError, FileNotFoundError) as e:
|