summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyload/Core.py10
-rw-r--r--pyload/config/default.conf1
-rw-r--r--pyload/network/JsEngine.py (renamed from pyload/utils/JsEngine.py)59
-rw-r--r--pyload/webui/__init__.py2
4 files changed, 43 insertions, 29 deletions
diff --git a/pyload/Core.py b/pyload/Core.py
index e6f4a0b5a..4d07bfe0f 100644
--- a/pyload/Core.py
+++ b/pyload/Core.py
@@ -30,7 +30,7 @@ from pyload.manager.event.PullEvents import PullManager
from pyload.network.RequestFactory import RequestFactory
from pyload.manager.thread.ServerThread import WebServer
from pyload.manager.event.Scheduler import Scheduler
-from pyload.utils.JsEngine import JsEngine
+from pyload.network.JsEngine import JsEngine
from pyload import remote
from pyload.manager.RemoteManager import RemoteManager
from pyload.database import DatabaseBackend, FileHandler
@@ -84,21 +84,21 @@ class Core(object):
from pyload.config.Setup import SetupAssistant as Setup
self.config = ConfigParser()
- s = Setup(pypath, self.config)
+ s = Setup(self.config)
s.set_user()
exit()
elif option in ("-s", "--setup"):
from pyload.config.Setup import SetupAssistant as Setup
self.config = ConfigParser()
- s = Setup(pypath, self.config)
+ s = Setup(self.config)
s.start()
exit()
elif option == "--changedir":
from pyload.config.Setup import SetupAssistant as Setup
self.config = ConfigParser()
- s = Setup(pypath, self.config)
+ s = Setup(self.config)
s.conf_path(True)
exit()
elif option in ("-q", "--quit"):
@@ -249,7 +249,7 @@ class Core(object):
print "This is your first start, running configuration assistent now."
self.config = ConfigParser()
- s = Setup(pypath, self.config)
+ s = Setup(self.config)
res = False
try:
res = s.start()
diff --git a/pyload/config/default.conf b/pyload/config/default.conf
index d1f39f481..773e800af 100644
--- a/pyload/config/default.conf
+++ b/pyload/config/default.conf
@@ -30,6 +30,7 @@ general - "General":
int min_free_space : "Min Free Space (MB)" = 200
bool folder_per_package : "Create folder for each package" = True
int renice : "CPU Priority" = 0
+ auto;common;pyv8;node;rhino;jsc jsengine : "JS Engine" = auto
download - "Download":
int chunks : "Max connections for one download" = 3
int max_downloads : "Max Parallel Downloads" = 3
diff --git a/pyload/utils/JsEngine.py b/pyload/network/JsEngine.py
index 459c53971..dfee29530 100644
--- a/pyload/utils/JsEngine.py
+++ b/pyload/network/JsEngine.py
@@ -12,14 +12,9 @@ from pyload.utils import encode, decode, uniqify
class JsEngine(object):
""" JS Engine superclass """
- def __init__(self, core, engine=None): #: engine can be a jse name """string""" or an AbstractEngine """class"""
-
- self.core = core
- self.engine = None #: Default engine Instance
-
- if not ENGINES:
- self.core.log.critical("No JS Engine found!")
- return
+ def __init__(self, core, engine=None):
+ self.core = core
+ self.engine = None #: Engine Instance
if not engine:
engine = self.core.config.get("general", "jsengine")
@@ -42,42 +37,47 @@ class JsEngine(object):
return [E for E in ENGINES if E.find()]
- def get(self, engine):
+ def get(self, engine=None):
""" Convert engine name (string) to relative JSE class (AbstractEngine extended) """
- if isinstance(engine, basestring):
+ if not engine:
+ JSE = self.engine
+
+ elif isinstance(engine, basestring):
engine_name = engine.lower()
for E in ENGINES:
if E.__name == engine_name: #: doesn't check if E(NGINE) is available, just convert string to class
JSE = E
break
else:
- JSE = None
+ raise ValueError("JSE")
+
elif issubclass(engine, AbstractEngine):
JSE = engine
+
else:
- JSE = None
+ raise TypeError("engine")
+
return JSE
def set(self, engine):
""" Set engine name (string) or JSE class (AbstractEngine extended) as default engine """
if isinstance(engine, basestring):
- self.set(self.get(engine))
+ return self.set(self.get(engine))
+
elif issubclass(engine, AbstractEngine) and engine.find():
self.engine = engine
return True
+
else:
return False
def eval(self, script, engine=None): #: engine can be a jse name """string""" or an AbstractEngine """class"""
- if not engine:
- JSE = self.engine
- else:
- JSE = self.get(engine)
+ JSE = self.get(engine)
if not JSE:
- return None
+ raise TypeError("engine")
script = encode(script)
@@ -108,19 +108,22 @@ class AbstractEngine(object):
__name = ""
+
def __init__(self):
self.setup()
self.available = self.find()
+
def setup(self):
pass
+
@classmethod
def find(cls):
""" Check if the engine is available """
try:
__import__(cls.__name)
- except ImportError:
+ except Exception:
try:
out, err = cls().eval("print(23+19)")
except Exception:
@@ -129,8 +132,9 @@ class AbstractEngine(object):
res = out == "42"
else:
res = True
- finally:
- return res
+
+ return res
+
def _eval(args):
if not self.available:
@@ -154,6 +158,7 @@ class Pyv8Engine(AbstractEngine):
__name = "pyv8"
+
def eval(self, script):
if not self.available:
return None, "JS Engine \"%s\" not found" % self.__name
@@ -164,17 +169,19 @@ class Pyv8Engine(AbstractEngine):
res = rt.eval(script), None #@TODO: parse stderr
except Exception, e:
res = None, e
- finally:
- return res
+
+ return res
class CommonEngine(AbstractEngine):
__name = "js"
+
def setup(self):
subprocess.Popen(["js", "-v"], bufsize=-1).communicate()
+
def eval(self, script):
script = "print(eval(unescape('%s')))" % quote(script)
args = ["js", "-e", script]
@@ -185,9 +192,11 @@ class NodeEngine(AbstractEngine):
__name = "nodejs"
+
def setup(self):
subprocess.Popen(["node", "-v"], bufsize=-1).communicate()
+
def eval(self, script):
script = "console.log(eval(unescape('%s')))" % quote(script)
args = ["node", "-e", script]
@@ -198,6 +207,7 @@ class RhinoEngine(AbstractEngine):
__name = "rhino"
+
def setup(self):
jspath = [
"/usr/share/java*/js.jar",
@@ -211,6 +221,7 @@ class RhinoEngine(AbstractEngine):
else:
self.path = ""
+
def eval(self, script):
script = "print(eval(unescape('%s')))" % quote(script)
args = ["java", "-cp", self.path, "org.mozilla.javascript.tools.shell.Main", "-e", script]
@@ -225,10 +236,12 @@ class JscEngine(AbstractEngine):
__name = "javascriptcore"
+
def setup(self):
jspath = "/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc"
self.path = jspath if path.exists(jspath) else ""
+
def eval(self, script):
script = "print(eval(unescape('%s')))" % quote(script)
args = [self.path, "-e", script]
diff --git a/pyload/webui/__init__.py b/pyload/webui/__init__.py
index 045c78e70..4f06d160e 100644
--- a/pyload/webui/__init__.py
+++ b/pyload/webui/__init__.py
@@ -26,7 +26,7 @@ SETUP = None
PYLOAD = None
from pyload.manager.thread import ServerThread
-from pyload.utils.JsEngine import JsEngine
+from pyload.network.JsEngine import JsEngine
if not ServerThread.core:
if ServerThread.setup: