summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--locale/generate_locale.py9
-rw-r--r--module/JsEngine.py55
2 files changed, 58 insertions, 6 deletions
diff --git a/locale/generate_locale.py b/locale/generate_locale.py
index f9cfd5033..cc2a064a6 100644
--- a/locale/generate_locale.py
+++ b/locale/generate_locale.py
@@ -11,7 +11,7 @@ options = ["--from-code=utf-8", "--copyright-holder=pyLoad Team", "--package-nam
###### Core
-EXCLUDE = ["BeautifulSoup.py", "module/gui", "web/locale", "web/ajax", "web/cnl", "web/pyload", "setup.py"]
+EXCLUDE = ["BeautifulSoup.py", "module/gui", "module/cli", "web/locale", "web/ajax", "web/cnl", "web/pyload", "setup.py"]
print "Generate core.pot"
f = open("includes.txt", "wb")
@@ -75,6 +75,13 @@ f = open("includes.txt", "wb")
f.write("./pyLoadCli.py\n")
f.close()
+for path, dir, filenames in walk("./module/cli"):
+ if [True for x in EXCLUDE if x in path]: continue
+ for file in filenames:
+ if file.endswith(".py") and file not in EXCLUDE:
+ f.write(join(path, file) + "\n")
+
+
call(["xgettext", "--files-from=includes.txt", "--default-domain=cli"] + options)
f = open("cli.po", "rb")
diff --git a/module/JsEngine.py b/module/JsEngine.py
index 2f34d54c0..3549595f7 100644
--- a/module/JsEngine.py
+++ b/module/JsEngine.py
@@ -18,6 +18,8 @@
"""
from imp import find_module
+from os.path import join, exists
+
ENGINE = ""
try:
@@ -36,8 +38,38 @@ if not ENGINE:
if not ENGINE:
try:
import subprocess
- subprocess.Popen(["js", "-v"], bufsize=-1,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- ENGINE = "js"
+
+ subprocess.Popen(["js", "-v"], bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
+ p = subprocess.Popen(["js", "-e", "print(23+19)"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ out, err = p.communicate()
+ #integrity check
+ if out.strip() == "42":
+ ENGINE = "js"
+ except:
+ pass
+
+
+if not ENGINE or ENGINE:
+ try:
+ path = "" #path where to find rhino
+
+ if exists("/usr/share/java/js.jar"):
+ path = "/usr/share/java/js.jar"
+ elif exists("js.jar"):
+ path = "js.jar"
+ elif exists(join(pypath, "js.jar")): #may raises an exception, but js.jar wasnt found anyway
+ path = join(pypath, "js.jar")
+
+ if not path:
+ raise Exception
+
+ import subprocess
+
+ p = subprocess.Popen(["java", "-cp", path, "org.mozilla.javascript.tools.shell.Main", "-e", "print(23+19)"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ out, err = p.communicate()
+ #integrity check
+ if out.strip() == "42":
+ ENGINE = "rhino"
except:
pass
@@ -54,9 +86,11 @@ class JsEngine():
if ENGINE == "spidermonkey":
import spidermonkey
global spidermonkey
+
elif ENGINE == "pyv8":
import PyV8
global PyV8
+
self.init = True
if not ENGINE:
@@ -67,6 +101,8 @@ class JsEngine():
return self.eval_pyv8(script)
elif ENGINE == "js":
return self.eval_js(script)
+ elif ENGINE == "rhino":
+ return self.eval_rhino(script)
def eval_spidermonkey(self, script):
@@ -80,9 +116,17 @@ class JsEngine():
return rt.eval(script)
def eval_js(self, script):
- script = "print(eval('%s'))" % script.replace("'",'"')
+ script = "print(eval('%s'))" % script.replace("'", '"')
p = subprocess.Popen(["js", "-e", script], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1)
- res = p.stdout.read().strip()
+ out, err = p.communicate()
+ res = out.strip()
+ return res
+
+ def eval_rhino(self, script):
+ script = "print(eval('%s'))" % script.replace("'", '"')
+ p = subprocess.Popen(["java", "-cp", path, "org.mozilla.javascript.tools.shell.Main", "-e", script], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1)
+ out, err = p.communicate()
+ res = out.strip()
return res
def error(self):
@@ -92,10 +136,11 @@ if __name__ == "__main__":
js = JsEngine()
import subprocess
import spidermonkey
- import PyV8
+ #import PyV8
test = '"a"+"b"'
print js.eval_js(test)
print js.eval_spidermonkey(test)
+ print js.eval_rhino(test)
print js.eval_pyv8(test) \ No newline at end of file