summaryrefslogtreecommitdiff
path: root/searx/plugins/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'searx/plugins/__init__.py')
-rw-r--r--searx/plugins/__init__.py61
1 files changed, 17 insertions, 44 deletions
diff --git a/searx/plugins/__init__.py b/searx/plugins/__init__.py
index 4c824da28..7815c2099 100644
--- a/searx/plugins/__init__.py
+++ b/searx/plugins/__init__.py
@@ -51,11 +51,7 @@ def sync_resource(base_path, resource_path, name, target_dir, plugin_dir):
dep_stat = stat(dep_path)
utime(resource_path, ns=(dep_stat.st_atime_ns, dep_stat.st_mtime_ns))
except IOError:
- logger.critical(
- "failed to copy plugin resource {0} for plugin {1}".format(
- file_name, name
- )
- )
+ logger.critical("failed to copy plugin resource {0} for plugin {1}".format(file_name, name))
sys.exit(3)
# returning with the web path of the resource
@@ -66,36 +62,28 @@ def prepare_package_resources(plugin, plugin_module_name):
plugin_base_path = dirname(abspath(plugin.__file__))
plugin_dir = plugin_module_name
- target_dir = join(
- settings["ui"]["static_path"], "plugins/external_plugins", plugin_dir
- )
+ target_dir = join(settings["ui"]["static_path"], "plugins/external_plugins", plugin_dir)
try:
makedirs(target_dir, exist_ok=True)
except IOError:
- logger.critical(
- "failed to create resource directory {0} for plugin {1}".format(
- target_dir, plugin_module_name
- )
- )
+ logger.critical("failed to create resource directory {0} for plugin {1}".format(target_dir, plugin_module_name))
sys.exit(3)
resources = []
if hasattr(plugin, "js_dependencies"):
resources.extend(map(basename, plugin.js_dependencies))
- plugin.js_dependencies = ([
- sync_resource(
- plugin_base_path, x, plugin_module_name, target_dir, plugin_dir
- ) for x in plugin.js_dependencies
- ])
+ plugin.js_dependencies = [
+ sync_resource(plugin_base_path, x, plugin_module_name, target_dir, plugin_dir)
+ for x in plugin.js_dependencies
+ ]
if hasattr(plugin, "css_dependencies"):
resources.extend(map(basename, plugin.css_dependencies))
- plugin.css_dependencies = ([
- sync_resource(
- plugin_base_path, x, plugin_module_name, target_dir, plugin_dir
- ) for x in plugin.css_dependencies
- ])
+ plugin.css_dependencies = [
+ sync_resource(plugin_base_path, x, plugin_module_name, target_dir, plugin_dir)
+ for x in plugin.css_dependencies
+ ]
for f in listdir(target_dir):
if basename(f) not in resources:
@@ -104,9 +92,7 @@ def prepare_package_resources(plugin, plugin_module_name):
remove(resource_path)
except IOError:
logger.critical(
- "failed to remove unused resource file {0} for plugin {1}".format(
- resource_path, plugin_module_name
- )
+ "failed to remove unused resource file {0} for plugin {1}".format(resource_path, plugin_module_name)
)
sys.exit(3)
@@ -137,9 +123,7 @@ def load_plugin(plugin_module_name, external):
for plugin_attr, plugin_attr_type in required_attrs:
if not hasattr(plugin, plugin_attr):
- logger.critical(
- '%s: missing attribute "%s", cannot load plugin', plugin, plugin_attr
- )
+ logger.critical('%s: missing attribute "%s", cannot load plugin', plugin, plugin_attr)
sys.exit(3)
attr = getattr(plugin, plugin_attr)
if not isinstance(attr, plugin_attr_type):
@@ -152,9 +136,7 @@ def load_plugin(plugin_module_name, external):
sys.exit(3)
for plugin_attr, plugin_attr_type in optional_attrs:
- if not hasattr(plugin, plugin_attr) or not isinstance(
- getattr(plugin, plugin_attr), plugin_attr_type
- ):
+ if not hasattr(plugin, plugin_attr) or not isinstance(getattr(plugin, plugin_attr), plugin_attr_type):
setattr(plugin, plugin_attr, plugin_attr_type())
if not hasattr(plugin, "preference_section"):
@@ -164,19 +146,12 @@ def load_plugin(plugin_module_name, external):
if plugin.preference_section == "query":
for plugin_attr in ("query_keywords", "query_examples"):
if not hasattr(plugin, plugin_attr):
- 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))
sys.exit(3)
if settings.get("enabled_plugins"):
# searx compatibility: plugin.name in settings['enabled_plugins']
- plugin.default_on = (
- plugin.name in settings["enabled_plugins"]
- or plugin.id in settings["enabled_plugins"]
- )
+ plugin.default_on = plugin.name in settings["enabled_plugins"] or plugin.id in settings["enabled_plugins"]
# copy ressources if this is an external plugin
if external:
@@ -193,9 +168,7 @@ def load_and_initialize_plugin(plugin_module_name, external, init_args):
try:
return plugin if plugin.init(*init_args) else None
except Exception: # pylint: disable=broad-except
- plugin.logger.exception(
- "Exception while calling init, the plugin is disabled"
- )
+ plugin.logger.exception("Exception while calling init, the plugin is disabled")
return None
return plugin