Browse Source

[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 years ago
parent
commit
9c91ab33f8
3 changed files with 21 additions and 10 deletions
  1. 18
    7
      searx/__init__.py
  2. 2
    2
      searx/utils.py
  3. 1
    1
      searx/webapp.py

+ 18
- 7
searx/__init__.py View File

18
 import certifi
18
 import certifi
19
 import logging
19
 import logging
20
 from os import environ
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
 from ssl import OPENSSL_VERSION_INFO, OPENSSL_VERSION
22
 from ssl import OPENSSL_VERSION_INFO, OPENSSL_VERSION
23
 try:
23
 try:
24
     from yaml import load
24
     from yaml import load
30
 searx_dir = abspath(dirname(__file__))
30
 searx_dir = abspath(dirname(__file__))
31
 engine_dir = dirname(realpath(__file__))
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
 if 'SEARX_SETTINGS_PATH' in environ:
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
 else:
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
 # load settings
52
 # load settings
42
 with open(settings_path) as settings_yaml:
53
 with open(settings_path) as settings_yaml:
67
     logging.basicConfig(level=logging.WARNING)
78
     logging.basicConfig(level=logging.WARNING)
68
 
79
 
69
 logger = logging.getLogger('searx')
80
 logger = logging.getLogger('searx')
70
-
81
+logger.debug('read configuration from %s', settings_path)
71
 # Workaround for openssl versions <1.0.2
82
 # Workaround for openssl versions <1.0.2
72
 # https://github.com/certifi/python-certifi/issues/26
83
 # https://github.com/certifi/python-certifi/issues/26
73
 if OPENSSL_VERSION_INFO[0:3] < (1, 0, 2):
84
 if OPENSSL_VERSION_INFO[0:3] < (1, 0, 2):

+ 2
- 2
searx/utils.py View File

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

+ 1
- 1
searx/webapp.py View File

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