Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: utils.py

Issue 29330389: Issue 2956 - Ensure the correct version of jsshell is present (Closed)
Patch Set: Base directory name on jsshell version, avoid checking which version the binary outputs Created Nov. 23, 2015, 12:39 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « .hgignore ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 7 import os
8 import platform 8 import platform
9 from StringIO import StringIO 9 from StringIO import StringIO
10 import sys 10 import sys
11 import urllib 11 import urllib
12 import zipfile 12 import zipfile
13 13
14 JSSHELL_VERSION = "31.5.0"
15 JSSHELL_URL = ("https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly"
16 "/2015/02/2015-02-25-00-22-19-mozilla-esr31/jsshell-%s.zip")
17
18 JSSHELL_SUPPORTED_PLATFORMS = {
19 "win32": "win32",
20 "linux2": {
21 "i686": "linux-i686",
22 "x86_64": "linux-x86_64"
23 },
24 "darwin": "mac"
25 }
26
14 def ensureJSShell(): 27 def ensureJSShell():
15 baseDir = os.path.dirname(__file__) 28 baseDir = os.path.dirname(__file__)
16 shell_dir = os.path.join(baseDir, 'mozilla') 29 shell_dir = os.path.join(baseDir, "jsshell-%s" % JSSHELL_VERSION)
Sebastian Noack 2015/11/23 12:53:58 With the new approach, hard-coding the version is
kzar 2015/11/23 13:20:21 Hmm I see what you mean, but on the other hand hav
Sebastian Noack 2015/11/23 13:27:48 How about following? JSSHELL_DIR = "mozilla-esr31
kzar 2015/11/23 13:38:12 That's better but still kind of sucks, the directo
Sebastian Noack 2015/11/23 13:51:16 Then include the timestamp if that is your concern
Sebastian Noack 2015/11/23 13:51:16 Then include the timestamp if that is your concern
kzar 2015/11/23 14:01:31 Fine, Done.
30
17 if not os.path.exists(shell_dir): 31 if not os.path.exists(shell_dir):
18 os.makedirs(shell_dir) 32 os.makedirs(shell_dir)
19 if sys.platform == 'win32': 33 if sys.platform == 'win32':
20 path = os.path.join(shell_dir, 'js.exe') 34 path = os.path.join(shell_dir, 'js.exe')
21 else: 35 else:
22 path = os.path.join(shell_dir, 'js') 36 path = os.path.join(shell_dir, 'js')
37
23 if os.path.exists(path): 38 if os.path.exists(path):
24 return path 39 return path
25 40
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: 41 try:
35 build = supported_platforms[sys.platform] 42 build = JSSHELL_SUPPORTED_PLATFORMS[sys.platform]
36 if isinstance(build, dict): 43 if isinstance(build, dict):
37 build = build[platform.machine()] 44 build = build[platform.machine()]
38 except KeyError: 45 except KeyError:
39 raise Exception('Platform %s (%s) not supported by JS shell' % ( 46 raise Exception('Platform %s (%s) not supported by JS shell' % (
40 sys.platform, platform.machine() 47 sys.platform, platform.machine()
41 )) 48 ))
42 49
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 50 data = StringIO(urllib.urlopen(JSSHELL_URL % build).read())
Sebastian Noack 2015/11/23 12:53:58 While changing this code anyway, mind closing the
kzar 2015/11/23 13:20:21 Done.
44 data = StringIO(urllib.urlopen(download_url).read())
45 zip = zipfile.ZipFile(data) 51 zip = zipfile.ZipFile(data)
46 zip.extractall(shell_dir) 52 zip.extractall(shell_dir)
47 zip.close() 53 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
OLDNEW
« no previous file with comments | « .hgignore ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld