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: Use regexp to match version number and tidy things up Created Nov. 19, 2015, 10:45 a.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 | « no previous file | 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 import re
9 from StringIO import StringIO 10 from StringIO import StringIO
11 import shutil
12 import subprocess
10 import sys 13 import sys
11 import urllib 14 import urllib
12 import zipfile 15 import zipfile
13 16
17 JSSHELL_VERSION = "JavaScript-C31.5.0esrpre"
18 JSSHELL_URL = ("https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly"
19 "/2015/02/2015-02-25-00-22-19-mozilla-esr31/jsshell-%s.zip")
20
14 def ensureJSShell(): 21 def ensureJSShell():
15 baseDir = os.path.dirname(__file__) 22 baseDir = os.path.dirname(__file__)
16 shell_dir = os.path.join(baseDir, 'mozilla') 23 shell_dir = os.path.join(baseDir, 'mozilla')
24
17 if not os.path.exists(shell_dir): 25 if not os.path.exists(shell_dir):
18 os.makedirs(shell_dir) 26 os.makedirs(shell_dir)
19 if sys.platform == 'win32': 27 if sys.platform == 'win32':
20 path = os.path.join(shell_dir, 'js.exe') 28 path = os.path.join(shell_dir, 'js.exe')
21 else: 29 else:
22 path = os.path.join(shell_dir, 'js') 30 path = os.path.join(shell_dir, 'js')
31
23 if os.path.exists(path): 32 if os.path.exists(path):
24 return path 33 # Return the path if jsshell is present and its version is correct
34 match = re.search(r"^Version: (.+)$",
35 subprocess.check_output([path, "--help"]), re.MULTILINE)
36 if match and match.group(1) == JSSHELL_VERSION:
37 return path
38 # Otherwise remove the old / faulty version, we'll re-download
39 shutil.rmtree(shell_dir)
Sebastian Noack 2015/11/19 20:21:43 I'm not sure whether this is a good idea. Imagine
kzar 2015/11/20 09:02:00 That's true, but the current behaviour is to somew
40 os.makedirs(shell_dir)
25 41
26 supported_platforms = { 42 supported_platforms = {
27 'win32': 'win32', 43 'win32': 'win32',
28 'linux2': { 44 'linux2': {
29 'i686': 'linux-i686', 45 'i686': 'linux-i686',
30 'x86_64': 'linux-x86_64' 46 'x86_64': 'linux-x86_64'
31 }, 47 },
32 'darwin': 'mac', 48 'darwin': 'mac',
33 } 49 }
34 try: 50 try:
35 build = supported_platforms[sys.platform] 51 build = supported_platforms[sys.platform]
36 if isinstance(build, dict): 52 if isinstance(build, dict):
37 build = build[platform.machine()] 53 build = build[platform.machine()]
38 except KeyError: 54 except KeyError:
39 raise Exception('Platform %s (%s) not supported by JS shell' % ( 55 raise Exception('Platform %s (%s) not supported by JS shell' % (
40 sys.platform, platform.machine() 56 sys.platform, platform.machine()
41 )) 57 ))
42 58
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 59 data = StringIO(urllib.urlopen(JSSHELL_URL % build).read())
44 data = StringIO(urllib.urlopen(download_url).read())
45 zip = zipfile.ZipFile(data) 60 zip = zipfile.ZipFile(data)
46 zip.extractall(shell_dir) 61 zip.extractall(shell_dir)
47 zip.close() 62 zip.close()
48 63
49 if not os.path.exists(path): 64 if not os.path.exists(path):
50 raise Exception('Downloaded package didn\'t contain JS shell executable') 65 raise Exception('Downloaded package didn\'t contain JS shell executable')
51 66
52 try: 67 try:
53 os.chmod(path, 0700) 68 os.chmod(path, 0700)
54 except: 69 except:
55 pass 70 pass
56 71
57 return path 72 return path
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld