Bladeren bron

[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
Alexandre Flament 8 jaren geleden
bovenliggende
commit
9c91ab33f8
3 gewijzigde bestanden met toevoegingen van 21 en 10 verwijderingen
  1. 18
    7
      searx/__init__.py
  2. 2
    2
      searx/utils.py
  3. 1
    1
      searx/webapp.py

+ 18
- 7
searx/__init__.py Bestand weergeven

@@ -18,7 +18,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
18 18
 import certifi
19 19
 import logging
20 20
 from os import environ
21
-from os.path import realpath, dirname, join, abspath
21
+from os.path import realpath, dirname, join, abspath, isfile
22 22
 from ssl import OPENSSL_VERSION_INFO, OPENSSL_VERSION
23 23
 try:
24 24
     from yaml import load
@@ -30,13 +30,24 @@ except:
30 30
 searx_dir = abspath(dirname(__file__))
31 31
 engine_dir = dirname(realpath(__file__))
32 32
 
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
35 41
 if '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'])
38 45
 else:
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')
40 51
 
41 52
 # load settings
42 53
 with open(settings_path) as settings_yaml:
@@ -67,7 +78,7 @@ else:
67 78
     logging.basicConfig(level=logging.WARNING)
68 79
 
69 80
 logger = logging.getLogger('searx')
70
-
81
+logger.debug('read configuration from %s', settings_path)
71 82
 # Workaround for openssl versions <1.0.2
72 83
 # https://github.com/certifi/python-certifi/issues/26
73 84
 if OPENSSL_VERSION_INFO[0:3] < (1, 0, 2):

+ 2
- 2
searx/utils.py Bestand weergeven

@@ -186,9 +186,9 @@ def get_resources_directory(searx_directory, subdirectory, resources_directory):
186 186
     return resources_directory
187 187
 
188 188
 
189
-def get_themes(static_path):
189
+def get_themes(templates_path):
190 190
     """Returns available themes list."""
191
-    themes = os.listdir(os.path.join(static_path, 'themes'))
191
+    themes = os.listdir(templates_path)
192 192
     if '__common__' in themes:
193 193
         themes.remove('__common__')
194 194
     return themes

+ 1
- 1
searx/webapp.py Bestand weergeven

@@ -100,7 +100,7 @@ static_files = get_static_files(static_path)
100 100
 default_theme = settings['ui']['default_theme']
101 101
 templates_path = get_resources_directory(searx_dir, 'templates', settings['ui']['templates_path'])
102 102
 logger.debug('templates directory is %s', templates_path)
103
-themes = get_themes(static_path)
103
+themes = get_themes(templates_path)
104 104
 result_templates = get_result_templates(templates_path)
105 105
 global_favicons = []
106 106
 for indice, theme in enumerate(themes):