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

Delta Between Two Patch Sets: utils.py

Issue 29330389: Issue 2956 - Ensure the correct version of jsshell is present (Closed)
Left Patch Set: Created Nov. 18, 2015, 2:56 p.m.
Right Patch Set: Remove JSSHELL_VERSION variable Created Nov. 23, 2015, 1:58 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « .hgignore ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 import os 8 import os
8 import platform 9 import platform
9 from StringIO import StringIO 10 from StringIO import StringIO
10 import shutil
11 import subprocess
12 import sys 11 import sys
13 import urllib 12 import urllib
14 import zipfile 13 import zipfile
15 14
15 JSSHELL_DIR = "mozilla-esr31"
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)
18
19 JSSHELL_SUPPORTED_PLATFORMS = {
20 "win32": "win32",
21 "linux2": {
22 "i686": "linux-i686",
23 "x86_64": "linux-x86_64"
24 },
25 "darwin": "mac"
26 }
27
16 def ensureJSShell(): 28 def ensureJSShell():
17 baseDir = os.path.dirname(__file__) 29 baseDir = os.path.dirname(__file__)
18 shell_dir = os.path.join(baseDir, 'mozilla') 30 shell_dir = os.path.join(baseDir, JSSHELL_DIR)
19 31
20 if not os.path.exists(shell_dir): 32 if not os.path.exists(shell_dir):
21 os.makedirs(shell_dir) 33 os.makedirs(shell_dir)
22 if sys.platform == 'win32': 34 if sys.platform == 'win32':
23 path = os.path.join(shell_dir, 'js.exe') 35 path = os.path.join(shell_dir, 'js.exe')
24 else: 36 else:
25 path = os.path.join(shell_dir, 'js') 37 path = os.path.join(shell_dir, 'js')
26 38
27 if os.path.exists(path): 39 if os.path.exists(path):
28 # Return the path if jsshell is present and its version is correct 40 return path
29 try:
30 version = [s for s in subprocess.check_output([path, "--help"]).split("\n" )
Sebastian Noack 2015/11/18 19:53:37 This can be simplified: m = re.search(r"^Versio
kzar 2015/11/19 10:56:41 Done.
31 if s.startswith("Version")][0].split()[1]
32 except (IndexError, subprocess.CalledProcessError):
33 pass
34 else:
35 if version == "JavaScript-C31.5.0esrpre":
sergei 2015/11/18 15:30:06 Nit: I don't know the convention for buildtools bu
sergei 2015/11/18 15:30:06 Nit: In addition it seems better to show some warn
kzar 2015/11/18 15:40:49 Well I would have separated the version string fro
sergei 2015/11/18 15:50:18 I have missed it, in this case it's totally fine f
36 return path
37 # Otherwise remove the old / faulty version, we'll re-download
38 shutil.rmtree(shell_dir)
39 os.makedirs(shell_dir)
40 41
41 supported_platforms = {
42 'win32': 'win32',
43 'linux2': {
44 'i686': 'linux-i686',
45 'x86_64': 'linux-x86_64'
46 },
47 'darwin': 'mac',
48 }
49 try: 42 try:
50 build = supported_platforms[sys.platform] 43 build = JSSHELL_SUPPORTED_PLATFORMS[sys.platform]
51 if isinstance(build, dict): 44 if isinstance(build, dict):
52 build = build[platform.machine()] 45 build = build[platform.machine()]
53 except KeyError: 46 except KeyError:
54 raise Exception('Platform %s (%s) not supported by JS shell' % ( 47 raise Exception('Platform %s (%s) not supported by JS shell' % (
55 sys.platform, platform.machine() 48 sys.platform, platform.machine()
56 )) 49 ))
57 50
58 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 51 with closing(urllib.urlopen(JSSHELL_URL % build)) as response, \
59 data = StringIO(urllib.urlopen(download_url).read()) 52 zipfile.ZipFile(StringIO(response.read())) as zip:
60 zip = zipfile.ZipFile(data) 53 zip.extractall(shell_dir)
61 zip.extractall(shell_dir)
62 zip.close()
63 54
64 if not os.path.exists(path): 55 if not os.path.exists(path):
65 raise Exception('Downloaded package didn\'t contain JS shell executable') 56 raise Exception('Downloaded package didn\'t contain JS shell executable')
66 57
67 try: 58 try:
68 os.chmod(path, 0700) 59 os.chmod(path, 0700)
69 except: 60 except:
70 pass 61 pass
71 62
72 return path 63 return path
LEFTRIGHT
« .hgignore ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld