summaryrefslogtreecommitdiffstats
path: root/module/JsEngine.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/JsEngine.py')
-rw-r--r--module/JsEngine.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/module/JsEngine.py b/module/JsEngine.py
index ca5bfe4fc..2f34d54c0 100644
--- a/module/JsEngine.py
+++ b/module/JsEngine.py
@@ -17,17 +17,18 @@
@author: RaNaN
"""
+from imp import find_module
ENGINE = ""
try:
- import spidermonkey
+ find_module("spidermonkey")
ENGINE = "spidermonkey"
except:
pass
if not ENGINE:
try:
- import PyV8
+ find_module("PyV8")
ENGINE = "pyv8"
except:
pass
@@ -43,11 +44,21 @@ if not ENGINE:
class JsEngine():
def __init__(self):
self.engine = ENGINE
+ self.init = False
def __nonzero__(self):
return False if not ENGINE else True
def eval(self, script):
+ if not self.init:
+ if ENGINE == "spidermonkey":
+ import spidermonkey
+ global spidermonkey
+ elif ENGINE == "pyv8":
+ import PyV8
+ global PyV8
+ self.init = True
+
if not ENGINE:
raise Exception("No JS Engine")
elif ENGINE == "spidermonkey":
@@ -74,6 +85,9 @@ class JsEngine():
res = p.stdout.read().strip()
return res
+ def error(self):
+ return _("No js engine detected, please install either Spidermonkey, ossp-js or pyv8")
+
if __name__ == "__main__":
js = JsEngine()
import subprocess