From e04659853af2fb18242f4c40224e4cf1b5c2daed Mon Sep 17 00:00:00 2001 From: Martin Minka Date: Sat, 15 Jan 2022 13:01:30 +0100 Subject: [PATCH 1/2] [enh] add blocked_plugins setting do completly remove plugin from query processing --- searx/plugins/__init__.py | 5 ++++- searx/settings.yml | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/searx/plugins/__init__.py b/searx/plugins/__init__.py index 6c1bea8d0..98117dd28 100644 --- a/searx/plugins/__init__.py +++ b/searx/plugins/__init__.py @@ -226,7 +226,10 @@ def plugin_module_names(): def initialize(app): + # it is possible to block plugins from being registered into plugin chain + blocked_plugins = settings['outgoing'].get('blocked_plugins', []) + for module_name, external in plugin_module_names(): plugin = load_and_initialize_plugin(module_name, external, (app, settings)) - if plugin: + if plugin and plugin.name not in blocked_plugins: plugins.register(plugin) diff --git a/searx/settings.yml b/searx/settings.yml index 0ea69007a..a9f96e9ca 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -157,6 +157,12 @@ outgoing: # - plugin2 # - ... +# Plugins listed here will be loaded, but will not be registered into plugins chain. +# The engine will not use them to process queries. +# +# blocked_plugins: +# - 'Self Informations' + # Comment or un-comment plugin to activate / deactivate by default. # # enabled_plugins: From a6c8780891f72a632ebe30d9abcec2712a09aa72 Mon Sep 17 00:00:00 2001 From: Martin Minka Date: Sat, 15 Jan 2022 20:15:39 +0100 Subject: [PATCH 2/2] improvements based on code review from @dalf --- searx/plugins/__init__.py | 11 +++++------ searx/settings.yml | 4 ++-- searx/settings_defaults.py | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/searx/plugins/__init__.py b/searx/plugins/__init__.py index 98117dd28..45fc9da6e 100644 --- a/searx/plugins/__init__.py +++ b/searx/plugins/__init__.py @@ -226,10 +226,9 @@ def plugin_module_names(): def initialize(app): - # it is possible to block plugins from being registered into plugin chain - blocked_plugins = settings['outgoing'].get('blocked_plugins', []) - for module_name, external in plugin_module_names(): - plugin = load_and_initialize_plugin(module_name, external, (app, settings)) - if plugin and plugin.name not in blocked_plugins: - plugins.register(plugin) + # it is possible to block plugins from being registered into plugin chain in settings.yml + if module_name not in settings['blocked_plugins']: + plugin = load_and_initialize_plugin(module_name, external, (app, settings)) + if plugin: + plugins.register(plugin) diff --git a/searx/settings.yml b/searx/settings.yml index a9f96e9ca..acb07a6cb 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -160,8 +160,8 @@ outgoing: # Plugins listed here will be loaded, but will not be registered into plugins chain. # The engine will not use them to process queries. # -# blocked_plugins: -# - 'Self Informations' +#blocked_plugins: +# - searx.plugins.self_info # Comment or un-comment plugin to activate / deactivate by default. # diff --git a/searx/settings_defaults.py b/searx/settings_defaults.py index ff556e3bb..64edd2323 100644 --- a/searx/settings_defaults.py +++ b/searx/settings_defaults.py @@ -212,6 +212,7 @@ SCHEMA = { }, 'plugins': SettingsValue(list, []), 'enabled_plugins': SettingsValue((None, list), None), + 'blocked_plugins': SettingsValue(list, []), 'checker': { 'off_when_debug': SettingsValue(bool, True), },