Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 os, platform, sys, urllib, zipfile | 7 import os |
Wladimir Palant
2015/07/02 17:48:31
Feel free to convert this to one per line while at
kzar
2015/07/03 13:08:50
Done.
| |
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 supported_platforms = { | 26 supported_platforms = { |
23 'win32': 'win32', | 27 'win32': 'win32', |
24 'linux2': { | 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
| |
25 '32bit': 'linux-i686', | 29 'i686': 'linux-i686', |
26 '64bit': 'linux-x86_64' | 30 'x86_64': 'linux-x86_64' |
27 }, | 31 }, |
28 'darwin': 'mac', | 32 'darwin': 'mac', |
29 } | 33 } |
30 try: | 34 try: |
31 build = supported_platforms[sys.platform] | 35 build = supported_platforms[sys.platform] |
32 if isinstance(build, dict): | 36 if isinstance(build, dict): |
33 build = build[platform.architecture()[0]] | 37 build = build[platform.machine()] |
Wladimir Palant
2015/07/02 17:48:31
This will give you the architecture of the Python
kzar
2015/07/03 13:08:50
Done.
| |
34 except KeyError: | 38 except KeyError: |
35 raise Exception('Platform %s (%s) not supported by JS shell' % ( | 39 raise Exception('Platform %s (%s) not supported by JS shell' % ( |
36 sys.platform, platform.architecture()[0] | 40 sys.platform, platform.machine() |
37 )) | 41 )) |
38 | 42 |
39 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 | 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 |
40 data = StringIO(urllib.urlopen(download_url).read()) | 44 data = StringIO(urllib.urlopen(download_url).read()) |
41 zip = zipfile.ZipFile(data) | 45 zip = zipfile.ZipFile(data) |
42 zip.extractall(shell_dir) | 46 zip.extractall(shell_dir) |
43 zip.close() | 47 zip.close() |
44 | 48 |
45 if not os.path.exists(path): | 49 if not os.path.exists(path): |
46 raise Exception('Downloaded package didn\'t contain JS shell executable') | 50 raise Exception('Downloaded package didn\'t contain JS shell executable') |
47 | 51 |
48 try: | 52 try: |
49 os.chmod(path, 0700) | 53 os.chmod(path, 0700) |
50 except: | 54 except: |
51 pass | 55 pass |
52 | 56 |
53 return path | 57 return path |
LEFT | RIGHT |