logo

searx

Unnamed repository; edit this file 'description' to name the repository.
commit: 88425f05d6c0e6124c625e52c684ef57f6a46827
parent: 8d9edfbe374ab98721193711b906b3398b6bffba
Author: asciimoo <asciimoo@gmail.com>
Date:   Fri, 31 Jan 2014 15:45:18 +0100

[enh] shortcut support added to engines

Diffstat:

searx/engines/__init__.py | 28+++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py @@ -36,6 +36,8 @@ engines = {} categories = {'general': []} +engine_shortcuts = {} + def load_module(filename): modname = splitext(filename)[0] @@ -54,13 +56,6 @@ for engine_data in settings['engines']: engine_name = engine_data['engine'] engine = load_module(engine_name + '.py') - if not hasattr(engine, 'paging'): - engine.paging = False - - if not hasattr(engine, 'language_support'): - #engine.language_support = False - engine.language_support = True - for param_name in engine_data: if param_name == 'engine': continue @@ -72,12 +67,26 @@ for engine_data in settings['engines']: str.strip, engine_data['categories'].split(',')) continue setattr(engine, param_name, engine_data[param_name]) + + if not hasattr(engine, 'paging'): + engine.paging = False + + if not hasattr(engine, 'language_support'): + #engine.language_support = False + engine.language_support = True + + if not hasattr(engine, 'shortcut'): + #engine.language_support = False + engine.shortcut = '' + + # checking required variables for engine_attr in dir(engine): if engine_attr.startswith('_'): continue if getattr(engine, engine_attr) is None: 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, @@ -86,12 +95,17 @@ for engine_data in settings['engines']: 'score_count': 0, 'errors': 0 } + if hasattr(engine, 'categories'): for category_name in engine.categories: categories.setdefault(category_name, []).append(engine) else: categories['general'].append(engine) + if engine.shortcut: + # TODO check duplications + engine_shortcuts[engine.shortcut] = engine.name + def default_request_params(): return {