forked from zaclys/searxng
[enh] shortcut support added to engines
This commit is contained in:
parent
8d9edfbe37
commit
88425f05d6
|
@ -36,6 +36,8 @@ engines = {}
|
||||||
|
|
||||||
categories = {'general': []}
|
categories = {'general': []}
|
||||||
|
|
||||||
|
engine_shortcuts = {}
|
||||||
|
|
||||||
|
|
||||||
def load_module(filename):
|
def load_module(filename):
|
||||||
modname = splitext(filename)[0]
|
modname = splitext(filename)[0]
|
||||||
|
@ -54,13 +56,6 @@ for engine_data in settings['engines']:
|
||||||
engine_name = engine_data['engine']
|
engine_name = engine_data['engine']
|
||||||
engine = load_module(engine_name + '.py')
|
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:
|
for param_name in engine_data:
|
||||||
if param_name == 'engine':
|
if param_name == 'engine':
|
||||||
continue
|
continue
|
||||||
|
@ -72,12 +67,26 @@ for engine_data in settings['engines']:
|
||||||
str.strip, engine_data['categories'].split(','))
|
str.strip, engine_data['categories'].split(','))
|
||||||
continue
|
continue
|
||||||
setattr(engine, param_name, engine_data[param_name])
|
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):
|
for engine_attr in dir(engine):
|
||||||
if engine_attr.startswith('_'):
|
if engine_attr.startswith('_'):
|
||||||
continue
|
continue
|
||||||
if getattr(engine, engine_attr) is None:
|
if getattr(engine, engine_attr) is None:
|
||||||
print '[E] Engine config error: Missing attribute "{0}.{1}"'.format(engine.name, engine_attr) # noqa
|
print '[E] Engine config error: Missing attribute "{0}.{1}"'.format(engine.name, engine_attr) # noqa
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
engines[engine.name] = engine
|
engines[engine.name] = engine
|
||||||
engine.stats = {
|
engine.stats = {
|
||||||
'result_count': 0,
|
'result_count': 0,
|
||||||
|
@ -86,12 +95,17 @@ for engine_data in settings['engines']:
|
||||||
'score_count': 0,
|
'score_count': 0,
|
||||||
'errors': 0
|
'errors': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasattr(engine, 'categories'):
|
if hasattr(engine, 'categories'):
|
||||||
for category_name in engine.categories:
|
for category_name in engine.categories:
|
||||||
categories.setdefault(category_name, []).append(engine)
|
categories.setdefault(category_name, []).append(engine)
|
||||||
else:
|
else:
|
||||||
categories['general'].append(engine)
|
categories['general'].append(engine)
|
||||||
|
|
||||||
|
if engine.shortcut:
|
||||||
|
# TODO check duplications
|
||||||
|
engine_shortcuts[engine.shortcut] = engine.name
|
||||||
|
|
||||||
|
|
||||||
def default_request_params():
|
def default_request_params():
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue