on master help sign in
[mod] settings.yml can be /etc/searx/settings.yml

The exact order is * first from SEARX_SETTINGS_PATH, * if not found then from searx code base, * if not found then from /etc/searx/settings.yml * if not found an exception stops searx loading

commit9c91ab33f8f89f15e45301cc6f4b28fe3e3e72d5 authorAlexandre Flament <alex@al-f.net> dateFri 6 Jan 2017, 13:52 (10 years ago) parentee080fe
3 files changed+21−10
searx/__init__.py+18−7 searx/utils.py+2−2 searx/webapp.py+1−1
searx/__init__.py+18−7
@@ -18,7 +18,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
1818import certifi
1919import logging
2020from os import environ
21−from os.path import realpath, dirname, join, abspath
21+from os.path import realpath, dirname, join, abspath, isfile
2222from ssl import OPENSSL_VERSION_INFO, OPENSSL_VERSION
2323try:
2424 from yaml import load
@@ -30,13 +30,24 @@ except:
3030searx_dir = abspath(dirname(__file__))
3131engine_dir = dirname(realpath(__file__))
3232
33−# if possible set path to settings using the
34−# enviroment variable SEARX_SETTINGS_PATH
33+
34+def check_settings_yml(file_name):
35+ if isfile(file_name):
36+ return file_name
37+ else:
38+ return None
39+
40+# find location of settings.yml
3541if 'SEARX_SETTINGS_PATH' in environ:
36− settings_path = environ['SEARX_SETTINGS_PATH']
37−# otherwise using default path
42+ # if possible set path to settings using the
43+ # enviroment variable SEARX_SETTINGS_PATH
44+ settings_path = check_settings_yml(environ['SEARX_SETTINGS_PATH'])
3845else:
39− settings_path = join(searx_dir, 'settings.yml')
46+ # if not, get it from searx code base or last solution from /etc/searx
47+ settings_path = check_settings_yml(join(searx_dir, 'settings.yml')) or check_settings_yml('/etc/searx/settings.yml')
48+
49+if not settings_path:
50+ raise Exception('settings.yml not found')
4051
4152# load settings
4253with open(settings_path) as settings_yaml:
@@ -67,7 +78,7 @@ else:
6778 logging.basicConfig(level=logging.WARNING)
6879
6980logger = logging.getLogger('searx')
70−
81+logger.debug('read configuration from %s', settings_path)
7182# Workaround for openssl versions <1.0.2
7283# https://github.com/certifi/python-certifi/issues/26
7384if OPENSSL_VERSION_INFO[0:3] < (1, 0, 2):
searx/utils.py+2−2
@@ -186,9 +186,9 @@ def get_resources_directory(searx_directory, subdirectory, resources_directory):
186186 return resources_directory
187187
188188
189−def get_themes(static_path):
189+def get_themes(templates_path):
190190 """Returns available themes list."""
191− themes = os.listdir(os.path.join(static_path, 'themes'))
191+ themes = os.listdir(templates_path)
192192 if '__common__' in themes:
193193 themes.remove('__common__')
194194 return themes
searx/webapp.py+1−1
@@ -100,7 +100,7 @@ static_files = get_static_files(static_path)
100100default_theme = settings['ui']['default_theme']
101101templates_path = get_resources_directory(searx_dir, 'templates', settings['ui']['templates_path'])
102102logger.debug('templates directory is %s', templates_path)
103−themes = get_themes(static_path)
103+themes = get_themes(templates_path)
104104result_templates = get_result_templates(templates_path)
105105global_favicons = []
106106for indice, theme in enumerate(themes):