mirror of
https://github.com/searxng/searxng.git
synced 2024-11-22 20:17:45 +01:00
[enh][mod] engines.cfg support
This commit is contained in:
parent
75a2a6fb73
commit
39d229e110
@ -17,37 +17,51 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
from os.path import realpath, dirname, splitext, join
|
from os.path import realpath, dirname, splitext, join
|
||||||
from os import listdir
|
|
||||||
from imp import load_source
|
from imp import load_source
|
||||||
import grequests
|
import grequests
|
||||||
from itertools import izip_longest, chain
|
from itertools import izip_longest, chain
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from searx import settings
|
from searx import settings
|
||||||
|
import ConfigParser
|
||||||
|
import sys
|
||||||
|
|
||||||
engine_dir = dirname(realpath(__file__))
|
engine_dir = dirname(realpath(__file__))
|
||||||
|
searx_dir = join(engine_dir, '../../')
|
||||||
|
|
||||||
|
engines_config = ConfigParser.SafeConfigParser()
|
||||||
|
engines_config.read(join(searx_dir, 'engines.cfg'))
|
||||||
|
|
||||||
engines = {}
|
engines = {}
|
||||||
|
|
||||||
categories = {'general': []}
|
categories = {'general': []}
|
||||||
|
|
||||||
for filename in listdir(engine_dir):
|
def load_module(filename):
|
||||||
if filename.startswith('_') or not filename.endswith('.py'):
|
|
||||||
continue
|
|
||||||
modname = splitext(filename)[0]
|
modname = splitext(filename)[0]
|
||||||
if modname in settings.blacklist:
|
if modname in sys.modules:
|
||||||
continue
|
del sys.modules[modname]
|
||||||
filepath = join(engine_dir, filename)
|
filepath = join(engine_dir, filename)
|
||||||
engine = load_source(modname, filepath)
|
module = load_source(modname, filepath)
|
||||||
engine.name = modname
|
module.name = modname
|
||||||
if not hasattr(engine, 'request') or not hasattr(engine, 'response'):
|
return module
|
||||||
continue
|
|
||||||
engines[modname] = engine
|
for section in engines_config.sections():
|
||||||
if not hasattr(engine, 'categories'):
|
engine_data = engines_config.options(section)
|
||||||
categories['general'].append(engine)
|
engine = load_module(engines_config.get(section, 'engine')+'.py')
|
||||||
else:
|
engine.name = section
|
||||||
|
for param_name in engine_data:
|
||||||
|
if param_name == 'engine':
|
||||||
|
continue
|
||||||
|
if param_name == 'categories':
|
||||||
|
engine.categories = map(str.strip, engines_config.get(section, param_name).split(','))
|
||||||
|
continue
|
||||||
|
setattr(engine, param_name, engines_config.get(section, param_name))
|
||||||
|
engines[engine.name] = engine
|
||||||
|
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:
|
||||||
|
categories['general'].append(engine)
|
||||||
|
|
||||||
def default_request_params():
|
def default_request_params():
|
||||||
return {'method': 'GET', 'headers': {}, 'data': {}, 'url': '', 'cookies': {}}
|
return {'method': 'GET', 'headers': {}, 'data': {}, 'url': '', 'cookies': {}}
|
||||||
|
Loading…
Reference in New Issue
Block a user