|
@@ -43,9 +43,7 @@ DEFAULT_PLUGINS_PATH_LIST = ['./plugins']
|
43
|
43
|
MANDATORY_VARNAMES = [PLUGIN_NAME_VARNAME, LOADER_FILENAME_VARNAME,
|
44
|
44
|
PLUGIN_VERSION_VARNAME]
|
45
|
45
|
|
46
|
|
-DEFAULT_PLUGIN_TYPE = 'extension'
|
47
|
|
-PLUGINS_TYPES = [DEFAULT_PLUGIN_TYPE, 'datasource', 'session_handler', 'ui']
|
48
|
|
-
|
|
46
|
+DEFAULT_PLUGIN_TYPE = 'extension' #Value found in lodel/plugin/extensions.py::Extensions._type_conf_name
|
49
|
47
|
|
50
|
48
|
##@brief Describe and handle version numbers
|
51
|
49
|
class PluginVersion(object):
|
|
@@ -149,37 +147,38 @@ to generic PluginVersion comparison function : '%s'" % cmp_fun_name)
|
149
|
147
|
return {'major': self.major, 'minor': self.minor,
|
150
|
148
|
'revision': self.revision}
|
151
|
149
|
|
152
|
|
-##@brief Stores plugin class registered
|
153
|
|
-__all_ptypes = list()
|
154
|
|
-
|
155
|
150
|
##@brief Plugin metaclass that allows to "catch" child class
|
156
|
151
|
#declaration
|
157
|
152
|
#
|
158
|
153
|
#Automatic script registration on child class declaration
|
159
|
154
|
class MetaPlugType(type):
|
160
|
|
-
|
|
155
|
+
|
|
156
|
+ ##@brief Dict storing all plugin types
|
|
157
|
+ #
|
|
158
|
+ #key is the _type_conf_name and value is the class
|
|
159
|
+ _all_ptypes = dict()
|
|
160
|
+
|
161
|
161
|
def __init__(self, name, bases, attrs):
|
162
|
162
|
#Here we can store all child classes of Plugin
|
163
|
163
|
super().__init__(name, bases, attrs)
|
164
|
164
|
if len(bases) == 1 and bases[0] == object:
|
165
|
165
|
return
|
166
|
|
- self.__register_types()
|
167
|
|
- #list_name= [cls.__name__ for cls in __all_ptypes]
|
168
|
|
- #if self.name in list_name:
|
169
|
|
- # return
|
170
|
|
- #else:
|
171
|
|
- # plug_type_register(self)
|
172
|
|
-
|
173
|
|
- def __register_types(self):
|
174
|
|
- plug_type_register(self)
|
|
166
|
+ #Regitering a new plugin type
|
|
167
|
+ MetaPlugType._all_ptypes[self._type_conf_name] = self
|
175
|
168
|
|
176
|
|
-def plug_type_register(cls):
|
177
|
|
- __all_ptypes.append(cls)
|
178
|
|
- logger.info("New child class registered : %s" % cls.__name__)
|
|
169
|
+ @classmethod
|
|
170
|
+ def all_types(cls):
|
|
171
|
+ return copy.copy(cls._all_ptypes)
|
179
|
172
|
|
180
|
|
-def all_types():
|
181
|
|
- return copy.copy(__all_ptypes)
|
|
173
|
+ @classmethod
|
|
174
|
+ def all_ptype_names(cls):
|
|
175
|
+ return list(cls._all_ptypes.keys())
|
182
|
176
|
|
|
177
|
+ @classmethod
|
|
178
|
+ def type_from_name(cls, ptype_name):
|
|
179
|
+ if ptype_name not in cls._all_ptypes:
|
|
180
|
+ raise PluginError("Unknown plugin type '%s'" % ptype_name)
|
|
181
|
+ return cls._all_ptypes[ptype_name]
|
183
|
182
|
|
184
|
183
|
##@brief Handle plugins
|
185
|
184
|
#
|
|
@@ -212,6 +211,11 @@ class Plugin(object, metaclass=MetaPlugType):
|
212
|
211
|
#where plugin list is stored
|
213
|
212
|
_plist_confspecs = None
|
214
|
213
|
|
|
214
|
+ ##@brief The name of the plugin type in the confguration
|
|
215
|
+ #
|
|
216
|
+ #None in abstract classes and implemented by child classes
|
|
217
|
+ _type_conf_name = None
|
|
218
|
+
|
215
|
219
|
##@brief Plugin class constructor
|
216
|
220
|
#
|
217
|
221
|
# Called by setting in early stage of lodel2 boot sequence using classmethod
|
|
@@ -290,7 +294,8 @@ class Plugin(object, metaclass=MetaPlugType):
|
290
|
294
|
except AttributeError:
|
291
|
295
|
self.__type = DEFAULT_PLUGIN_TYPE
|
292
|
296
|
self.__type = str(self.__type).lower()
|
293
|
|
- if self.__type not in PLUGINS_TYPES:
|
|
297
|
+ if self.__type not in MetaPlugType.all_ptype_names():
|
|
298
|
+ print("FUCK : ", MetaPlugType.all_ptype_names())
|
294
|
299
|
raise PluginError("Unknown plugin type '%s'" % self.__type)
|
295
|
300
|
# Load plugin name from init file (just for checking)
|
296
|
301
|
try:
|
|
@@ -427,6 +432,9 @@ name differ from the one found in plugin's init file"
|
427
|
432
|
logger.debug("Plugin '%s' loaded" % self.name)
|
428
|
433
|
self.loaded = True
|
429
|
434
|
|
|
435
|
+ ##@brief Returns the loader module
|
|
436
|
+ #
|
|
437
|
+ #Accessor for the __loader__ python module
|
430
|
438
|
def loader_module(self):
|
431
|
439
|
if not self.loaded:
|
432
|
440
|
raise RuntimeError("Plugin %s not loaded yet."%self.name)
|
|
@@ -535,10 +543,10 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
|
535
|
543
|
raise PluginError("No plugin named %s found" % plugin_name)
|
536
|
544
|
pinfos = pdcache['plugins'][plugin_name]
|
537
|
545
|
ptype = pinfos['type']
|
538
|
|
- if ptype == 'datasource':
|
539
|
|
- pcls = DatasourcePlugin
|
540
|
|
- else:
|
541
|
|
- pcls = cls
|
|
546
|
+ if ptype not in MetaPlugType.all_ptype_names():
|
|
547
|
+ raise PluginError("Unknown plugin type '%s'" % ptype)
|
|
548
|
+ pcls = MetaPlugType.type_from_name(ptype)
|
|
549
|
+ print("\n\n\nINSTANCIATING : ", pcls, " from name : ", ptype)
|
542
|
550
|
plugin = pcls(plugin_name)
|
543
|
551
|
cls._plugin_instances[plugin_name] = plugin
|
544
|
552
|
logger.debug("Plugin %s available." % plugin)
|
|
@@ -655,7 +663,7 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
|
655
|
663
|
##@brief Return a list of child Class Plugin
|
656
|
664
|
@classmethod
|
657
|
665
|
def plugin_types(cls):
|
658
|
|
- return all_types()
|
|
666
|
+ return MetaPlugType.all_types()
|
659
|
667
|
|
660
|
668
|
##@brief Attempt to open and load plugin discover cache
|
661
|
669
|
#@return discover cache
|