mirror of
https://github.com/searxng/searxng.git
synced 2024-12-30 05:00:29 +00:00
[enh] plugin attribute type check
This commit is contained in:
parent
f7c18a04ac
commit
bf5d6f56c6
1 changed files with 6 additions and 5 deletions
|
@ -4,14 +4,15 @@ from sys import exit
|
||||||
|
|
||||||
logger = logger.getChild('plugins')
|
logger = logger.getChild('plugins')
|
||||||
|
|
||||||
required_attrs = ('name',
|
required_attrs = (('name', str),
|
||||||
'description',
|
('description', str),
|
||||||
'default_on')
|
('default_on', bool))
|
||||||
|
|
||||||
|
|
||||||
class Plugin():
|
class Plugin():
|
||||||
default_on = False
|
default_on = False
|
||||||
name = 'Default plugin'
|
name = 'Default plugin'
|
||||||
|
description = 'Default plugin description'
|
||||||
|
|
||||||
|
|
||||||
class PluginStore():
|
class PluginStore():
|
||||||
|
@ -25,8 +26,8 @@ class PluginStore():
|
||||||
|
|
||||||
def register(self, *plugins):
|
def register(self, *plugins):
|
||||||
for plugin in plugins:
|
for plugin in plugins:
|
||||||
for plugin_attr in required_attrs:
|
for plugin_attr, plugin_attr_type in required_attrs:
|
||||||
if not hasattr(plugin, plugin_attr):
|
if not hasattr(plugin, plugin_attr) or not isinstance(getattr(plugin, plugin_attr), plugin_attr_type):
|
||||||
logger.critical('missing attribute "{0}", cannot load plugin: {1}'.format(plugin_attr, plugin))
|
logger.critical('missing attribute "{0}", cannot load plugin: {1}'.format(plugin_attr, plugin))
|
||||||
exit(3)
|
exit(3)
|
||||||
plugin.id = plugin.name.replace(' ', '_')
|
plugin.id = plugin.name.replace(' ', '_')
|
||||||
|
|
Loading…
Reference in a new issue