| Index: utils.py |
| diff --git a/utils.py b/utils.py |
| index ac3014ae675e7cf67fd33965c7f4f5a2eb13195b..587c3b7a98c67b2a561530db865403eb7351b1f9 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_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.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') |