From 5944e13cf0a90466ecf8e59dfa9ea09adf5d0dcc Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Thu, 20 Feb 2020 22:01:20 +0530 Subject: [PATCH] searx: Update search engines for 0.16.0 - Handle gzipped example settings files - Fix yaml.load deprecation warnings Signed-off-by: Joseph Nuthalapati Reviewed-by: James Valleroy --- actions/searx | 12 +++++++++++- plinth/modules/searx/__init__.py | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/actions/searx b/actions/searx index 268fd05f1..5583808b5 100755 --- a/actions/searx +++ b/actions/searx @@ -5,6 +5,7 @@ Configuration helper for searx. """ import argparse +import gzip import os import pathlib import secrets @@ -119,7 +120,7 @@ def subcommand_get_safe_search(_): def read_settings(): """Load settings as dictionary from YAML config file.""" with open(SETTINGS_FILE, 'rb') as settings_file: - return yaml.load(settings_file) + return yaml.safe_load(settings_file) def write_settings(settings): @@ -136,6 +137,14 @@ def _get_example_settings_file(): return searx_doc_dir / 'settings.yml.gz' +def _update_search_engines(settings): + """Updates settings with the latest supported search engines.""" + example_settings_file = _get_example_settings_file() + open_func = gzip.open if example_settings_file.suffix == '.gz' else open + with open_func(example_settings_file, 'rb') as example_settings: + settings['engines'] = yaml.safe_load(example_settings)['engines'] + + def subcommand_setup(_): """Post installation actions for Searx""" _copy_uwsgi_configuration() @@ -154,6 +163,7 @@ def subcommand_setup(_): _set_title(settings) _set_timeout(settings) _set_safe_search(settings) + _update_search_engines(settings) write_settings(settings) action_utils.service_restart('uwsgi') diff --git a/plinth/modules/searx/__init__.py b/plinth/modules/searx/__init__.py index f705b5c8f..4f0276d66 100644 --- a/plinth/modules/searx/__init__.py +++ b/plinth/modules/searx/__init__.py @@ -17,7 +17,7 @@ from plinth.modules.users import register_group from .manifest import (PUBLIC_ACCESS_SETTING_FILE, # noqa, pylint: disable=unused-import backup, clients) -version = 3 +version = 4 managed_packages = ['searx', 'uwsgi', 'uwsgi-plugin-python3']