|
@@ -27,7 +27,7 @@ VIRTUAL_TEMP_PACKAGE_NAME = 'lodel.plugin_tmp'
|
27
|
27
|
##@brief Plugin init filename
|
28
|
28
|
INIT_FILENAME = '__init__.py' # Loaded with settings
|
29
|
29
|
PLUGIN_NAME_VARNAME = '__plugin_name__'
|
30
|
|
-PLUGIN_TYPE_VARNAME = '__type__'
|
|
30
|
+PLUGIN_TYPE_VARNAME = '__plugin_type__'
|
31
|
31
|
PLUGIN_VERSION_VARNAME = '__version__'
|
32
|
32
|
CONFSPEC_FILENAME_VARNAME = '__confspec__'
|
33
|
33
|
CONFSPEC_VARNAME = 'CONFSPEC'
|
|
@@ -42,8 +42,8 @@ DEFAULT_PLUGINS_PATH_LIST = ['./plugins']
|
42
|
42
|
MANDATORY_VARNAMES = [PLUGIN_NAME_VARNAME, LOADER_FILENAME_VARNAME,
|
43
|
43
|
PLUGIN_VERSION_VARNAME]
|
44
|
44
|
|
45
|
|
-EXTENSIONS = 'default'
|
46
|
|
-PLUGINS_TYPES = [EXTENSIONS, 'datasource', 'session_handler', 'ui']
|
|
45
|
+DEFAULT_PLUGIN_TYPE = 'extension'
|
|
46
|
+PLUGINS_TYPES = [DEFAULT_PLUGIN_TYPE, 'datasource', 'session_handler', 'ui']
|
47
|
47
|
|
48
|
48
|
|
49
|
49
|
##@brief Describe and handle version numbers
|
|
@@ -249,7 +249,7 @@ init file. Malformed plugin"
|
249
|
249
|
try:
|
250
|
250
|
self.__type = getattr(self.module, PLUGIN_TYPE_VARNAME)
|
251
|
251
|
except AttributeError:
|
252
|
|
- self.__type = EXTENSIONS
|
|
252
|
+ self.__type = DEFAULT_PLUGIN_TYPE
|
253
|
253
|
self.__type = str(self.__type).lower()
|
254
|
254
|
if self.__type not in PLUGINS_TYPES:
|
255
|
255
|
raise PluginError("Unknown plugin type '%s'" % self.__type)
|
|
@@ -427,6 +427,17 @@ name differ from the one found in plugin's init file"
|
427
|
427
|
def confspecs(self):
|
428
|
428
|
return copy.copy(self.__confspecs)
|
429
|
429
|
|
|
430
|
+ ##@brief Attempt to read plugin discover cache
|
|
431
|
+ #@note If no cache yet make a discover with default plugin directory
|
|
432
|
+ #@return a dict (see @ref _discover() )
|
|
433
|
+ @classmethod
|
|
434
|
+ def plugin_cache(cls):
|
|
435
|
+ if not os.path.isfile(DISCOVER_CACHE_FILENAME):
|
|
436
|
+ cls.discover()
|
|
437
|
+ with open(DISCOVER_CACHE_FILENAME) as pdcache_fd:
|
|
438
|
+ res = json.load(pdcache_fd)
|
|
439
|
+ return res
|
|
440
|
+
|
430
|
441
|
##@brief Register a new plugin
|
431
|
442
|
#
|
432
|
443
|
#@param plugin_name str : The plugin name
|
|
@@ -434,11 +445,23 @@ name differ from the one found in plugin's init file"
|
434
|
445
|
#@throw PluginError
|
435
|
446
|
@classmethod
|
436
|
447
|
def register(cls, plugin_name):
|
|
448
|
+ from .datasource_plugin import DatasourcePlugin
|
437
|
449
|
if plugin_name in cls._plugin_instances:
|
438
|
450
|
msg = "Plugin allready registered with same name %s"
|
439
|
451
|
msg %= plugin_name
|
440
|
452
|
raise PluginError(msg)
|
441
|
|
- plugin = cls(plugin_name)
|
|
453
|
+ #Here we check that previous discover found a plugin with that name
|
|
454
|
+ pdcache = cls.plugin_cache()
|
|
455
|
+ if plugin_name not in pdcache['plugins']:
|
|
456
|
+ raise PluginError("No plugin named %s found" % plugin_name)
|
|
457
|
+ pinfos = pdcache['plugins'][plugin_name]
|
|
458
|
+ ptype = pinfos['type']
|
|
459
|
+ if ptype == 'datasource':
|
|
460
|
+ pcls = DatasourcePlugin
|
|
461
|
+ else:
|
|
462
|
+ pcls = cls
|
|
463
|
+ print(plugin_name, ptype, pcls)
|
|
464
|
+ plugin = pcls(plugin_name)
|
442
|
465
|
cls._plugin_instances[plugin_name] = plugin
|
443
|
466
|
logger.debug("Plugin %s available." % plugin)
|
444
|
467
|
return plugin
|
|
@@ -531,8 +554,7 @@ name differ from the one found in plugin's init file"
|
531
|
554
|
result = dict()
|
532
|
555
|
for pinfos in tmp_res:
|
533
|
556
|
pname = pinfos['name']
|
534
|
|
- if (
|
535
|
|
- pname in result
|
|
557
|
+ if ( pname in result
|
536
|
558
|
and pinfos['version'] > result[pname]['version'])\
|
537
|
559
|
or pname not in result:
|
538
|
560
|
result[pname] = pinfos
|
|
@@ -618,16 +640,23 @@ name differ from the one found in plugin's init file"
|
618
|
640
|
log_msg %= (attr_name, INIT_FILENAME)
|
619
|
641
|
logger.debug(log_msg)
|
620
|
642
|
return False
|
|
643
|
+ #Fetching plugin's version
|
621
|
644
|
try:
|
622
|
645
|
pversion = getattr(initmod, PLUGIN_VERSION_VARNAME)
|
623
|
|
- except PluginError as e:
|
|
646
|
+ except (NameError, AttributeError) as e:
|
624
|
647
|
msg = "Invalid plugin version found in %s : %s"
|
625
|
648
|
msg %= (path, e)
|
626
|
649
|
raise PluginError(msg)
|
|
650
|
+ #Fetching plugin's type
|
|
651
|
+ try:
|
|
652
|
+ ptype = getattr(initmod, PLUGIN_TYPE_VARNAME)
|
|
653
|
+ except (NameError, AttributeError) as e:
|
|
654
|
+ ptype = DEFAULT_PLUGIN_TYPE
|
627
|
655
|
pname = getattr(initmod, PLUGIN_NAME_VARNAME)
|
628
|
656
|
return {'name': pname,
|
629
|
657
|
'version': pversion,
|
630
|
|
- 'path': path}
|
|
658
|
+ 'path': path,
|
|
659
|
+ 'type': ptype}
|
631
|
660
|
|
632
|
661
|
##@brief Import init file from a plugin path
|
633
|
662
|
#@param path str : Directory path
|