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: Make sure to close the urllib response object Created Nov. 23, 2015, 1:15 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..4aac453e460778b6b095d5de0b2eabbb0b3be08f 100644
--- a/utils.py
+++ b/utils.py
@@ -4,35 +4,43 @@
# 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
import sys
import urllib
-import zipfile
+from zipfile import ZipFile
+
+JSSHELL_VERSION = "31.5.0"
+JSSHELL_URL = ("https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly"
+ "/2015/02/2015-02-25-00-22-19-mozilla-esr31/jsshell-%s.zip")
+
+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-%s" % JSSHELL_VERSION)
+
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(StringIO(urllib.urlopen(JSSHELL_URL % build).read())) as zip:
Sebastian Noack 2015/11/23 13:31:00 Ehmm... Guess what's wrong with that? ;)
kzar 2015/11/23 13:44:11 Argh, whoops!
+ 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