summaryrefslogtreecommitdiff
path: root/searx/utils.py
diff options
context:
space:
mode:
authorAdam Tauber <asciimoo@gmail.com>2016-11-19 17:51:19 +0100
committerAdam Tauber <asciimoo@gmail.com>2016-11-19 17:51:19 +0100
commit55dc538398090e437c5e495dddad983a7870d09b (patch)
tree6372edb5450684b3e1a575e20c74a61127394746 /searx/utils.py
parent827f9e41ca84638d873997001b53e7f4a62a78aa (diff)
downloadsearxng-55dc538398090e437c5e495dddad983a7870d09b.tar.gz
searxng-55dc538398090e437c5e495dddad983a7870d09b.zip
[mod] move load_module function to utils
Diffstat (limited to 'searx/utils.py')
-rw-r--r--searx/utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/searx/utils.py b/searx/utils.py
index 5039fa975..faa634853 100644
--- a/searx/utils.py
+++ b/searx/utils.py
@@ -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