Index: utils.py |
diff --git a/utils.py b/utils.py |
index ac3014ae675e7cf67fd33965c7f4f5a2eb13195b..743ead06185bf5c052de10735facb357783f8796 100644 |
--- a/utils.py |
+++ b/utils.py |
@@ -6,22 +6,38 @@ |
import os |
import platform |
+import re |
from StringIO import StringIO |
+import shutil |
+import subprocess |
import sys |
import urllib |
import zipfile |
+JSSHELL_VERSION = "JavaScript-C31.5.0esrpre" |
+JSSHELL_URL = ("https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly" |
+ "/2015/02/2015-02-25-00-22-19-mozilla-esr31/jsshell-%s.zip") |
+ |
def ensureJSShell(): |
baseDir = os.path.dirname(__file__) |
shell_dir = os.path.join(baseDir, 'mozilla') |
+ |
if not os.path.exists(shell_dir): |
os.makedirs(shell_dir) |
if sys.platform == 'win32': |
path = os.path.join(shell_dir, 'js.exe') |
else: |
path = os.path.join(shell_dir, 'js') |
+ |
if os.path.exists(path): |
- return path |
+ # Return the path if jsshell is present and its version is correct |
+ match = re.search(r"^Version: (.+)$", |
+ subprocess.check_output([path, "--help"]), re.MULTILINE) |
+ if match and match.group(1) == JSSHELL_VERSION: |
+ return path |
+ # Otherwise remove the old / faulty version, we'll re-download |
+ shutil.rmtree(shell_dir) |
Sebastian Noack
2015/11/19 20:21:43
I'm not sure whether this is a good idea. Imagine
kzar
2015/11/20 09:02:00
That's true, but the current behaviour is to somew
|
+ os.makedirs(shell_dir) |
supported_platforms = { |
'win32': 'win32', |
@@ -40,8 +56,7 @@ def ensureJSShell(): |
sys.platform, platform.machine() |
)) |
- download_url = 'https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/2015/02/2015-02-25-00-22-19-mozilla-esr31/jsshell-%s.zip' % build |
- data = StringIO(urllib.urlopen(download_url).read()) |
+ data = StringIO(urllib.urlopen(JSSHELL_URL % build).read()) |
zip = zipfile.ZipFile(data) |
zip.extractall(shell_dir) |
zip.close() |