| 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 from contextlib import closing |
| 8 import os | 8 import os |
| 9 import platform | 9 import platform |
| 10 from StringIO import StringIO | 10 from StringIO import StringIO |
| 11 import sys | 11 import sys |
| 12 import urllib | 12 import urllib |
| 13 import zipfile | 13 import zipfile |
| 14 | 14 |
| 15 JSSHELL_DIR = "mozilla-esr31" | 15 JSSHELL_DIR = "mozilla-esr31" |
| 16 JSSHELL_URL = ("https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly" | 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) | 17 "/2015/02/2015-02-25-00-22-19-%s/jsshell-%%s.zip" % JSSHELL_DIR) |
| 18 | 18 |
| 19 JSSHELL_SUPPORTED_PLATFORMS = { | 19 JSSHELL_SUPPORTED_PLATFORMS = { |
| 20 "win32": "win32", | 20 "win32": "win32", |
| 21 "linux2": { | 21 "linux2": { |
| 22 "i686": "linux-i686", | 22 "i686": "linux-i686", |
| 23 "x86_64": "linux-x86_64" | 23 "x86_64": "linux-x86_64" |
| 24 }, | 24 }, |
| 25 "darwin": "mac" | 25 "darwin": "mac" |
| 26 } | 26 } |
| 27 | 27 |
| 28 | 28 |
| 29 def ensureJSShell(): | 29 def ensureJSShell(): |
| 30 path = os.environ.get('SPIDERMONKEY_BINARY') |
| 31 if path and os.path.isfile(path): |
| 32 return path |
| 33 |
| 30 baseDir = os.path.dirname(__file__) | 34 baseDir = os.path.dirname(__file__) |
| 31 | 35 |
| 32 try: | 36 try: |
| 33 build = JSSHELL_SUPPORTED_PLATFORMS[sys.platform] | 37 build = JSSHELL_SUPPORTED_PLATFORMS[sys.platform] |
| 34 if isinstance(build, dict): | 38 if isinstance(build, dict): |
| 35 build = build[platform.machine()] | 39 build = build[platform.machine()] |
| 36 except KeyError: | 40 except KeyError: |
| 37 raise Exception('Platform %s (%s) not supported by JS shell' % ( | 41 raise Exception('Platform %s (%s) not supported by JS shell' % ( |
| 38 sys.platform, platform.machine() | 42 sys.platform, platform.machine() |
| 39 )) | 43 )) |
| 40 | 44 |
| 41 shell_dir = os.path.join(baseDir, JSSHELL_DIR + "-" + build) | 45 shell_dir = os.path.join(baseDir, JSSHELL_DIR + "-" + build) |
| 42 if not os.path.exists(shell_dir): | 46 if not os.path.exists(shell_dir): |
| 43 os.makedirs(shell_dir) | 47 os.makedirs(shell_dir) |
| 44 if sys.platform == 'win32': | 48 if sys.platform == 'win32': |
| 45 path = os.path.join(shell_dir, 'js.exe') | 49 path = os.path.join(shell_dir, 'js.exe') |
| 46 else: | 50 else: |
| 47 path = os.path.join(shell_dir, 'js') | 51 path = os.path.join(shell_dir, 'js') |
| 48 | 52 |
| 49 if os.path.exists(path): | 53 if os.path.exists(path): |
| 50 return path | 54 return path |
| 51 | 55 |
| 52 with closing(urllib.urlopen(JSSHELL_URL % build)) as response: | 56 with closing(urllib.urlopen(JSSHELL_URL % build)) as response: |
| 53 data = response.read() | 57 data = response.read() |
| 54 | 58 |
| 55 with zipfile.ZipFile(StringIO(data)) as zip: | 59 with zipfile.ZipFile(StringIO(data)) as zip: |
| 56 zip.extractall(shell_dir) | 60 zip.extractall(shell_dir) |
| 57 | 61 |
| 58 if not os.path.exists(path): | 62 if not os.path.exists(path): |
| 59 raise Exception('Downloaded package didn\'t contain JS shell executable'
) | 63 raise Exception('Downloaded package didn\'t contain JS shell executable'
) |
| 60 | 64 |
| 61 try: | 65 try: |
| 62 os.chmod(path, 0700) | 66 os.chmod(path, 0700) |
| 63 except: | 67 except: |
| 64 pass | 68 pass |
| 65 | 69 |
| 66 return path | 70 return path |
| OLD | NEW |