From 2cfa760b57748f427e65fbfb6cfff9a6299882b1 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Sat, 13 Dec 2014 19:26:40 +0100 Subject: [PATCH] [mod] engine load refactor --- searx/engines/__init__.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 80356a8cd..3c9ce3b57 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -41,11 +41,8 @@ def load_module(filename): module.name = modname return module -if 'engines' not in settings or not settings['engines']: - print '[E] Error no engines found. Edit your settings.yml' - exit(2) -for engine_data in settings['engines']: +def load_engine(engine_data): engine_name = engine_data['engine'] engine = load_module(engine_name + '.py') @@ -87,7 +84,6 @@ for engine_data in settings['engines']: print '[E] Engine config error: Missing attribute "{0}.{1}"'.format(engine.name, engine_attr) # noqa sys.exit(1) - engines[engine.name] = engine engine.stats = { 'result_count': 0, 'search_count': 0, @@ -105,6 +101,7 @@ for engine_data in settings['engines']: if engine.shortcut: # TODO check duplications engine_shortcuts[engine.shortcut] = engine.name + return engine def get_engines_stats(): @@ -194,3 +191,12 @@ def get_engines_stats(): sorted(errors, key=itemgetter('avg'), reverse=True) ), ] + + +if 'engines' not in settings or not settings['engines']: + print '[E] Error no engines found. Edit your settings.yml' + exit(2) + +for engine_data in settings['engines']: + engine = load_engine(engine_data) + engines[engine.name] = engine