| Left: | ||
| Right: |
| 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 import sys, os, urllib, zipfile | 7 import os |
| 8 import platform | |
| 8 from StringIO import StringIO | 9 from StringIO import StringIO |
| 10 import sys | |
| 11 import urllib | |
| 12 import zipfile | |
| 9 | 13 |
| 10 def ensureJSShell(): | 14 def ensureJSShell(): |
| 11 baseDir = os.path.dirname(__file__) | 15 baseDir = os.path.dirname(__file__) |
| 12 shell_dir = os.path.join(baseDir, 'mozilla') | 16 shell_dir = os.path.join(baseDir, 'mozilla') |
| 13 if not os.path.exists(shell_dir): | 17 if not os.path.exists(shell_dir): |
| 14 os.makedirs(shell_dir) | 18 os.makedirs(shell_dir) |
| 15 if sys.platform == 'win32': | 19 if sys.platform == 'win32': |
| 16 path = os.path.join(shell_dir, 'js.exe') | 20 path = os.path.join(shell_dir, 'js.exe') |
| 17 else: | 21 else: |
| 18 path = os.path.join(shell_dir, 'js') | 22 path = os.path.join(shell_dir, 'js') |
| 19 if os.path.exists(path): | 23 if os.path.exists(path): |
| 20 return path | 24 return path |
| 21 | 25 |
| 22 platform_map = { | 26 supported_platforms = { |
| 23 'win32': 'win32', | 27 'win32': 'win32', |
| 24 'linux2': 'linux-i686', | 28 'linux2': { |
|
Sebastian Noack
2015/07/03 14:31:44
How about following?
supported_platforms = {
..
kzar
2015/07/03 14:37:22
I did consider doing something like that but I thi
Sebastian Noack
2015/07/03 14:41:34
This is a good point. However, I don't like introd
| |
| 29 'i686': 'linux-i686', | |
| 30 'x86_64': 'linux-x86_64' | |
| 31 }, | |
| 25 'darwin': 'mac', | 32 'darwin': 'mac', |
| 26 } | 33 } |
| 27 if sys.platform not in platform_map: | 34 try: |
| 28 raise Exception('Unknown platform, is there a JS shell version for it?') | 35 build = supported_platforms[sys.platform] |
| 36 if isinstance(build, dict): | |
| 37 build = build[platform.machine()] | |
| 38 except KeyError: | |
| 39 raise Exception('Platform %s (%s) not supported by JS shell' % ( | |
| 40 sys.platform, platform.machine() | |
| 41 )) | |
| 29 | 42 |
| 30 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' % platform_map[sys.platform] | 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 |
| 31 data = StringIO(urllib.urlopen(download_url).read()) | 44 data = StringIO(urllib.urlopen(download_url).read()) |
| 32 zip = zipfile.ZipFile(data) | 45 zip = zipfile.ZipFile(data) |
| 33 zip.extractall(shell_dir) | 46 zip.extractall(shell_dir) |
| 34 zip.close() | 47 zip.close() |
| 35 | 48 |
| 36 if not os.path.exists(path): | 49 if not os.path.exists(path): |
| 37 raise Exception('Downloaded package didn\'t contain JS shell executable') | 50 raise Exception('Downloaded package didn\'t contain JS shell executable') |
| 38 | 51 |
| 39 try: | 52 try: |
| 40 os.chmod(path, 0700) | 53 os.chmod(path, 0700) |
| 41 except: | 54 except: |
| 42 pass | 55 pass |
| 43 | 56 |
| 44 return path | 57 return path |
| OLD | NEW |