Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: utils.py

Issue 29330389: Issue 2956 - Ensure the correct version of jsshell is present (Closed)
Patch Set: Remove JSSHELL_VERSION variable Created Nov. 23, 2015, 1:58 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « .hgignore ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils.py
diff --git a/utils.py b/utils.py
index ac3014ae675e7cf67fd33965c7f4f5a2eb13195b..c00776e6756469db9a9a49b110cef0e180b8a993 100644
--- a/utils.py
+++ b/utils.py
@@ -4,6 +4,7 @@
# version 2.0 (the "License"). You can obtain a copy of the License at
# http://mozilla.org/MPL/2.0/.
+from contextlib import closing
import os
import platform
from StringIO import StringIO
@@ -11,28 +12,35 @@ import sys
import urllib
import zipfile
+JSSHELL_DIR = "mozilla-esr31"
+JSSHELL_URL = ("https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly"
+ "/2015/02/2015-02-25-00-22-19-%s/jsshell-%%s.zip" % JSSHELL_DIR)
+
+JSSHELL_SUPPORTED_PLATFORMS = {
+ "win32": "win32",
+ "linux2": {
+ "i686": "linux-i686",
+ "x86_64": "linux-x86_64"
+ },
+ "darwin": "mac"
+}
+
def ensureJSShell():
baseDir = os.path.dirname(__file__)
- shell_dir = os.path.join(baseDir, 'mozilla')
+ shell_dir = os.path.join(baseDir, JSSHELL_DIR)
+
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
- supported_platforms = {
- 'win32': 'win32',
- 'linux2': {
- 'i686': 'linux-i686',
- 'x86_64': 'linux-x86_64'
- },
- 'darwin': 'mac',
- }
try:
- build = supported_platforms[sys.platform]
+ build = JSSHELL_SUPPORTED_PLATFORMS[sys.platform]
if isinstance(build, dict):
build = build[platform.machine()]
except KeyError:
@@ -40,11 +48,9 @@ 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())
- zip = zipfile.ZipFile(data)
- zip.extractall(shell_dir)
- zip.close()
+ with closing(urllib.urlopen(JSSHELL_URL % build)) as response, \
+ zipfile.ZipFile(StringIO(response.read())) as zip:
+ zip.extractall(shell_dir)
if not os.path.exists(path):
raise Exception('Downloaded package didn\'t contain JS shell executable')
« no previous file with comments | « .hgignore ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld