Browse Source

[enh] explicit engine init

Adam Tauber 8 years ago
parent
commit
a605377c40
2 changed files with 8 additions and 9 deletions
  1. 6
    8
      searx/engines/__init__.py
  2. 2
    1
      searx/webapp.py

+ 6
- 8
searx/engines/__init__.py View File

@@ -32,7 +32,6 @@ engine_dir = dirname(realpath(__file__))
32 32
 engines = {}
33 33
 
34 34
 categories = {'general': []}
35
-_initialized = False
36 35
 
37 36
 engine_shortcuts = {}
38 37
 engine_default_args = {'paging': False,
@@ -202,11 +201,10 @@ def get_engines_stats():
202 201
     ]
203 202
 
204 203
 
205
-if 'engines' not in settings or not settings['engines']:
206
-    logger.error('No engines found. Edit your settings.yml')
207
-    exit(2)
208
-
209
-for engine_data in settings['engines']:
210
-    engine = load_engine(engine_data)
211
-    if engine is not None:
204
+def initialize_engines(engine_list):
205
+    global categories, engines
206
+    engines = {}
207
+    categories = {'general': []}
208
+    for engine_data in engine_list:
209
+        engine = load_engine(engine_data)
212 210
         engines[engine.name] = engine

+ 2
- 1
searx/webapp.py View File

@@ -53,7 +53,7 @@ from flask_babel import Babel, gettext, format_date, format_decimal
53 53
 from flask.json import jsonify
54 54
 from searx import settings, searx_dir, searx_debug
55 55
 from searx.engines import (
56
-    categories, engines, get_engines_stats, engine_shortcuts
56
+    categories, engines, engine_shortcuts, get_engines_stats, initialize_engines
57 57
 )
58 58
 from searx.utils import (
59 59
     UnicodeWriter, highlight_content, html_to_text, get_themes,
@@ -765,6 +765,7 @@ def page_not_found(e):
765 765
 
766 766
 
767 767
 def run():
768
+    initialize_engines(settings['engines'])
768 769
     app.run(
769 770
         debug=searx_debug,
770 771
         use_debugger=searx_debug,