forked from zaclys/searxng
[mod] move load_module function to utils
This commit is contained in:
parent
827f9e41ca
commit
55dc538398
|
@ -16,13 +16,13 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
|||
(C) 2013- by Adam Tauber, <asciimoo@gmail.com>
|
||||
'''
|
||||
|
||||
from os.path import realpath, dirname, splitext, join
|
||||
from os.path import realpath, dirname
|
||||
import sys
|
||||
from imp import load_source
|
||||
from flask_babel import gettext
|
||||
from operator import itemgetter
|
||||
from searx import settings
|
||||
from searx import logger
|
||||
from searx.utils import load_module
|
||||
|
||||
|
||||
logger = logger.getChild('engines')
|
||||
|
@ -32,6 +32,7 @@ engine_dir = dirname(realpath(__file__))
|
|||
engines = {}
|
||||
|
||||
categories = {'general': []}
|
||||
_initialized = False
|
||||
|
||||
engine_shortcuts = {}
|
||||
engine_default_args = {'paging': False,
|
||||
|
@ -46,16 +47,6 @@ engine_default_args = {'paging': False,
|
|||
'time_range_support': False}
|
||||
|
||||
|
||||
def load_module(filename):
|
||||
modname = splitext(filename)[0]
|
||||
if modname in sys.modules:
|
||||
del sys.modules[modname]
|
||||
filepath = join(engine_dir, filename)
|
||||
module = load_source(modname, filepath)
|
||||
module.name = modname
|
||||
return module
|
||||
|
||||
|
||||
def load_engine(engine_data):
|
||||
|
||||
if '_' in engine_data['name']:
|
||||
|
@ -65,7 +56,7 @@ def load_engine(engine_data):
|
|||
engine_module = engine_data['engine']
|
||||
|
||||
try:
|
||||
engine = load_module(engine_module + '.py')
|
||||
engine = load_module(engine_module + '.py', engine_dir)
|
||||
except:
|
||||
logger.exception('Cannot load engine "{}"'.format(engine_module))
|
||||
return None
|
||||
|
|
|
@ -6,7 +6,10 @@ import re
|
|||
from babel.dates import format_date
|
||||
from codecs import getincrementalencoder
|
||||
from HTMLParser import HTMLParser
|
||||
from imp import load_source
|
||||
from os.path import splitext, join
|
||||
from random import choice
|
||||
import sys
|
||||
|
||||
from searx.version import VERSION_STRING
|
||||
from searx.languages import language_codes
|
||||
|
@ -285,3 +288,13 @@ def is_valid_lang(lang):
|
|||
if l[1].lower() == lang.lower():
|
||||
return (True, l[0][:2], l[1].lower())
|
||||
return False
|
||||
|
||||
|
||||
def load_module(filename, module_dir):
|
||||
modname = splitext(filename)[0]
|
||||
if modname in sys.modules:
|
||||
del sys.modules[modname]
|
||||
filepath = join(module_dir, filename)
|
||||
module = load_source(modname, filepath)
|
||||
module.name = modname
|
||||
return module
|
||||
|
|
Loading…
Reference in New Issue