Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 # This Source Code is subject to the terms of the Mozilla Public License | 1 # This Source Code is subject to the terms of the Mozilla Public License |
2 # version 2.0 (the "License"). You can obtain a copy of the License at | 2 # version 2.0 (the "License"). You can obtain a copy of the License at |
3 # http://mozilla.org/MPL/2.0/. | 3 # http://mozilla.org/MPL/2.0/. |
4 | 4 |
5 import os | 5 import os |
6 import platform | 6 import platform |
7 import io | 7 import io |
8 import zipfile | 8 import zipfile |
9 | 9 |
10 try: | 10 try: |
11 from urllib.request import urlopen | 11 from urllib.request import urlopen |
12 except ImportError: | 12 except ImportError: |
13 import urllib | 13 import urllib2 |
Sebastian Noack
2016/08/30 11:44:39
It seems more resonable to fallback to urllib2 (ra
Vasily Kuznetsov
2016/08/30 13:16:30
Acknowledged.
| |
14 import contextlib | 14 import contextlib |
15 | 15 |
16 def urlopen(*args, **kwargs): | 16 def urlopen(*args, **kwargs): |
17 return contextlib.closing(urllib.urlopen(*args, **kwargs)) | 17 return contextlib.closing(urllib2.urlopen(*args, **kwargs)) |
18 | 18 |
19 JSSHELL_DIR = 'mozilla-esr31' | 19 JSSHELL_DIR = 'mozilla-esr31' |
20 JSSHELL_URL = ('https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly' | 20 JSSHELL_URL = ('https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly' |
21 '/2015/02/2015-02-25-00-22-19-{}' | 21 '/2015/02/2015-02-25-00-22-19-{}' |
22 '/jsshell-{{}}.zip'.format(JSSHELL_DIR)) | 22 '/jsshell-{{}}.zip'.format(JSSHELL_DIR)) |
23 | 23 |
24 JSSHELL_SUPPORTED_PLATFORMS = { | 24 JSSHELL_SUPPORTED_PLATFORMS = { |
25 'Windows': 'win32', | 25 'Windows': 'win32', |
26 'Linux': { | 26 'Linux': { |
27 'i686': 'linux-i686', | 27 'i686': 'linux-i686', |
28 'x86_64': 'linux-x86_64' | 28 'x86_64': 'linux-x86_64' |
29 }, | 29 }, |
30 'Darwin': 'mac' | 30 'Darwin': 'mac' |
31 } | 31 } |
32 | 32 |
33 | 33 |
34 def ensureJSShell(): | 34 def ensureJSShell(): |
35 path = os.environ.get('SPIDERMONKEY_BINARY') | 35 path = os.environ.get('SPIDERMONKEY_BINARY') |
36 if path and os.path.isfile(path): | 36 if path and os.path.isfile(path): |
37 return path | 37 return path |
38 | 38 |
39 baseDir = os.path.dirname(__file__) | 39 baseDir = os.path.dirname(__file__) |
40 system = platform.system() | 40 system = platform.system() |
Sebastian Noack
2016/08/28 22:36:14
sys.platform behaves inconsistently since Python 3
Vasily Kuznetsov
2016/08/29 15:29:52
Acknowledged.
| |
41 | 41 |
42 try: | 42 try: |
43 build = JSSHELL_SUPPORTED_PLATFORMS[system] | 43 build = JSSHELL_SUPPORTED_PLATFORMS[system] |
44 if isinstance(build, dict): | 44 if isinstance(build, dict): |
45 build = build[platform.machine()] | 45 build = build[platform.machine()] |
46 except KeyError: | 46 except KeyError: |
47 raise Exception('Platform {} ({}) not supported by JS shell'.format( | 47 raise Exception('Platform {} ({}) not supported by JS shell'.format( |
48 system, platform.machine() | 48 system, platform.machine() |
49 )) | 49 )) |
50 | 50 |
(...skipping 16 matching lines...) Expand all Loading... | |
67 | 67 |
68 if not os.path.exists(path): | 68 if not os.path.exists(path): |
69 raise Exception('Downloaded package didn\'t contain JS shell executable' ) | 69 raise Exception('Downloaded package didn\'t contain JS shell executable' ) |
70 | 70 |
71 try: | 71 try: |
72 os.chmod(path, 0o700) | 72 os.chmod(path, 0o700) |
73 except: | 73 except: |
74 pass | 74 pass |
75 | 75 |
76 return path | 76 return path |
LEFT | RIGHT |