OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This Source Code is subject to the terms of the Mozilla Public License | 3 # This Source Code is subject to the terms of the Mozilla Public License |
4 # version 2.0 (the "License"). You can obtain a copy of the License at | 4 # version 2.0 (the "License"). You can obtain a copy of the License at |
5 # http://mozilla.org/MPL/2.0/. | 5 # http://mozilla.org/MPL/2.0/. |
6 | 6 |
| 7 from contextlib import closing |
7 import os | 8 import os |
8 import platform | 9 import platform |
9 from StringIO import StringIO | 10 from StringIO import StringIO |
10 import sys | 11 import sys |
11 import urllib | 12 import urllib |
12 import zipfile | 13 import zipfile |
13 | 14 |
| 15 JSSHELL_DIR = "mozilla-esr31" |
| 16 JSSHELL_URL = ("https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly" |
| 17 "/2015/02/2015-02-25-00-22-19-%s/jsshell-%%s.zip" % JSSHELL_DIR) |
| 18 |
| 19 JSSHELL_SUPPORTED_PLATFORMS = { |
| 20 "win32": "win32", |
| 21 "linux2": { |
| 22 "i686": "linux-i686", |
| 23 "x86_64": "linux-x86_64" |
| 24 }, |
| 25 "darwin": "mac" |
| 26 } |
| 27 |
14 def ensureJSShell(): | 28 def ensureJSShell(): |
15 baseDir = os.path.dirname(__file__) | 29 baseDir = os.path.dirname(__file__) |
16 shell_dir = os.path.join(baseDir, 'mozilla') | 30 shell_dir = os.path.join(baseDir, JSSHELL_DIR) |
| 31 |
17 if not os.path.exists(shell_dir): | 32 if not os.path.exists(shell_dir): |
18 os.makedirs(shell_dir) | 33 os.makedirs(shell_dir) |
19 if sys.platform == 'win32': | 34 if sys.platform == 'win32': |
20 path = os.path.join(shell_dir, 'js.exe') | 35 path = os.path.join(shell_dir, 'js.exe') |
21 else: | 36 else: |
22 path = os.path.join(shell_dir, 'js') | 37 path = os.path.join(shell_dir, 'js') |
| 38 |
23 if os.path.exists(path): | 39 if os.path.exists(path): |
24 return path | 40 return path |
25 | 41 |
26 supported_platforms = { | |
27 'win32': 'win32', | |
28 'linux2': { | |
29 'i686': 'linux-i686', | |
30 'x86_64': 'linux-x86_64' | |
31 }, | |
32 'darwin': 'mac', | |
33 } | |
34 try: | 42 try: |
35 build = supported_platforms[sys.platform] | 43 build = JSSHELL_SUPPORTED_PLATFORMS[sys.platform] |
36 if isinstance(build, dict): | 44 if isinstance(build, dict): |
37 build = build[platform.machine()] | 45 build = build[platform.machine()] |
38 except KeyError: | 46 except KeyError: |
39 raise Exception('Platform %s (%s) not supported by JS shell' % ( | 47 raise Exception('Platform %s (%s) not supported by JS shell' % ( |
40 sys.platform, platform.machine() | 48 sys.platform, platform.machine() |
41 )) | 49 )) |
42 | 50 |
43 download_url = 'https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/2015/0
2/2015-02-25-00-22-19-mozilla-esr31/jsshell-%s.zip' % build | 51 with closing(urllib.urlopen(JSSHELL_URL % build)) as response, \ |
44 data = StringIO(urllib.urlopen(download_url).read()) | 52 zipfile.ZipFile(StringIO(response.read())) as zip: |
45 zip = zipfile.ZipFile(data) | 53 zip.extractall(shell_dir) |
46 zip.extractall(shell_dir) | |
47 zip.close() | |
48 | 54 |
49 if not os.path.exists(path): | 55 if not os.path.exists(path): |
50 raise Exception('Downloaded package didn\'t contain JS shell executable') | 56 raise Exception('Downloaded package didn\'t contain JS shell executable') |
51 | 57 |
52 try: | 58 try: |
53 os.chmod(path, 0700) | 59 os.chmod(path, 0700) |
54 except: | 60 except: |
55 pass | 61 pass |
56 | 62 |
57 return path | 63 return path |
OLD | NEW |