|
@@ -11,6 +11,7 @@ import plugins
|
11
|
11
|
from lodel import logger
|
12
|
12
|
from lodel.settings.utils import SettingsError
|
13
|
13
|
from .exceptions import *
|
|
14
|
+from lodel.exceptions import *
|
14
|
15
|
|
15
|
16
|
## @package lodel.plugins Lodel2 plugins management
|
16
|
17
|
#
|
|
@@ -161,7 +162,6 @@ class MetaPlugType(type):
|
161
|
162
|
#Here we can store all child classes of Plugin
|
162
|
163
|
super().__init__(name, bases, attrs)
|
163
|
164
|
if len(bases) == 1 and bases[0] == object:
|
164
|
|
- print("Dropped : ", name, bases)
|
165
|
165
|
return
|
166
|
166
|
self.__register_types()
|
167
|
167
|
#list_name= [cls.__name__ for cls in __all_ptypes]
|
|
@@ -177,6 +177,9 @@ def plug_type_register(cls):
|
177
|
177
|
__all_ptypes.append(cls)
|
178
|
178
|
logger.info("New child class registered : %s" % cls.__name__)
|
179
|
179
|
|
|
180
|
+def all_types():
|
|
181
|
+ return copy.copy(__all_ptypes)
|
|
182
|
+
|
180
|
183
|
|
181
|
184
|
##@brief Handle plugins
|
182
|
185
|
#
|
|
@@ -204,6 +207,10 @@ class Plugin(object, metaclass=MetaPlugType):
|
204
|
207
|
|
205
|
208
|
##@brief Store dict representation of discover cache content
|
206
|
209
|
_discover_cache = None
|
|
210
|
+
|
|
211
|
+ #@brief Designed to store, in child classes, the confspec indicating \
|
|
212
|
+ #where plugin list is stored
|
|
213
|
+ _plist_confspecs = None
|
207
|
214
|
|
208
|
215
|
##@brief Plugin class constructor
|
209
|
216
|
#
|
|
@@ -213,7 +220,7 @@ class Plugin(object, metaclass=MetaPlugType):
|
213
|
220
|
# @param plugin_name str : plugin name
|
214
|
221
|
# @throw PluginError
|
215
|
222
|
def __init__(self, plugin_name):
|
216
|
|
- self.started()
|
|
223
|
+
|
217
|
224
|
self.name = plugin_name
|
218
|
225
|
self.path = self.plugin_path(plugin_name)
|
219
|
226
|
|
|
@@ -272,9 +279,9 @@ class Plugin(object, metaclass=MetaPlugType):
|
272
|
279
|
#PLUGIN_VERSION_VARNAME in init file is mandatory
|
273
|
280
|
self.__version = getattr(self.module, PLUGIN_VERSION_VARNAME)
|
274
|
281
|
except AttributeError:
|
275
|
|
- msg = "Error that should not append : no %s found in plugin \
|
276
|
|
-init file. Malformed plugin"
|
277
|
|
- msg %= PLUGIN_VERSION_VARNAME
|
|
282
|
+ msg = "Error that should not append while loading plugin '%s': no \
|
|
283
|
+%s found in plugin init file. Malformed plugin"
|
|
284
|
+ msg %= (plugin_name, PLUGIN_VERSION_VARNAME)
|
278
|
285
|
raise LodelFatalError(msg)
|
279
|
286
|
|
280
|
287
|
# Load plugin type
|
|
@@ -459,6 +466,13 @@ name differ from the one found in plugin's init file"
|
459
|
466
|
def confspecs(self):
|
460
|
467
|
return copy.copy(self.__confspecs)
|
461
|
468
|
|
|
469
|
+ @classmethod
|
|
470
|
+ def plist_confspecs(cls):
|
|
471
|
+ if cls._plist_confspecs is None:
|
|
472
|
+ raise LodelFatalError('Unitialized _plist_confspecs attribute for \
|
|
473
|
+%s' % cls.__name__)
|
|
474
|
+ return copy.copy(cls._plist_confspecs)
|
|
475
|
+
|
462
|
476
|
##@brief Retrieves plugin list confspecs
|
463
|
477
|
#
|
464
|
478
|
#This method ask for each Plugin child class the confspecs specifying where
|
|
@@ -525,7 +539,6 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
|
525
|
539
|
pcls = DatasourcePlugin
|
526
|
540
|
else:
|
527
|
541
|
pcls = cls
|
528
|
|
- print(plugin_name, ptype, pcls)
|
529
|
542
|
plugin = pcls(plugin_name)
|
530
|
543
|
cls._plugin_instances[plugin_name] = plugin
|
531
|
544
|
logger.debug("Plugin %s available." % plugin)
|
|
@@ -550,7 +563,7 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
|
550
|
563
|
# @return the plugin directory path
|
551
|
564
|
@classmethod
|
552
|
565
|
def plugin_path(cls, plugin_name):
|
553
|
|
- cls.started()
|
|
566
|
+
|
554
|
567
|
plist = cls.plugin_list()
|
555
|
568
|
if plugin_name not in plist:
|
556
|
569
|
raise PluginError("No plugin named '%s' found" % plugin_name)
|
|
@@ -572,25 +585,10 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
|
572
|
585
|
#
|
573
|
586
|
# This method load path and preload plugins
|
574
|
587
|
@classmethod
|
575
|
|
- def start(cls, plugins_directories, plugins):
|
576
|
|
- if cls._plugin_directories is not None:
|
577
|
|
- return
|
578
|
|
- import inspect
|
579
|
|
- self_path = inspect.getsourcefile(Plugin)
|
580
|
|
- default_plugin_path = os.path.abspath(self_path + '../../../../plugins')
|
581
|
|
- if plugins_directories is None:
|
582
|
|
- plugins_directories = list()
|
583
|
|
- plugins_directories += [ default_plugin_path ]
|
584
|
|
- cls._plugin_directories = list(set(plugins_directories))
|
|
588
|
+ def start(cls, plugins):
|
585
|
589
|
for plugin_name in plugins:
|
586
|
590
|
cls.register(plugin_name)
|
587
|
591
|
|
588
|
|
- @classmethod
|
589
|
|
- def started(cls, raise_if_not = True):
|
590
|
|
- res = cls._plugin_directories is not None
|
591
|
|
- if raise_if_not and not res:
|
592
|
|
- raise RuntimeError("Class Plugins is not initialized")
|
593
|
|
-
|
594
|
592
|
@classmethod
|
595
|
593
|
def clear(cls):
|
596
|
594
|
if cls._plugin_directories is not None:
|
|
@@ -657,7 +655,7 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
|
657
|
655
|
##@brief Return a list of child Class Plugin
|
658
|
656
|
@classmethod
|
659
|
657
|
def plugin_types(cls):
|
660
|
|
- return cls.__all_ptypes
|
|
658
|
+ return all_types()
|
661
|
659
|
|
662
|
660
|
##@brief Attempt to open and load plugin discover cache
|
663
|
661
|
#@return discover cache
|
|
@@ -880,31 +878,3 @@ with %s" % (custom_method._method_name, custom_method))
|
880
|
878
|
custom_method.__get_method())
|
881
|
879
|
logger.debug(
|
882
|
880
|
"Custom method %s added to target" % custom_method)
|
883
|
|
-
|
884
|
|
-
|
885
|
|
-##@page lodel2_plugins Lodel2 plugins system
|
886
|
|
-#
|
887
|
|
-# @par Plugin structure
|
888
|
|
-#A plugin is a package (a folder containing, at least, an __init__.py file.
|
889
|
|
-#This file should expose multiple things :
|
890
|
|
-# - a CONFSPEC variable containing configuration specifications
|
891
|
|
-# - an _activate() method that returns True if the plugin can be activated (
|
892
|
|
-# optionnal)
|
893
|
|
-#
|
894
|
|
-
|
895
|
|
-
|
896
|
|
-class SessionHandler(Plugin):
|
897
|
|
- __instance = None
|
898
|
|
-
|
899
|
|
- def __init__(self, plugin_name):
|
900
|
|
- if self.__instance is None:
|
901
|
|
- super(Plugin, self).__init__(plugin_name)
|
902
|
|
- self.__instance = True
|
903
|
|
- else:
|
904
|
|
- raise RuntimeError("A SessionHandler Plugin is already plug")
|
905
|
|
-
|
906
|
|
-class InterfacePlugin(Plugin):
|
907
|
|
- def __init__(self, plugin_name):
|
908
|
|
- super(Plugin, self).__init__(plugin_name)
|
909
|
|
-
|
910
|
|
-
|