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: Base directory name on jsshell version, avoid checking which version the binary outputs Created Nov. 23, 2015, 12:39 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 sys 11 import sys
11 import urllib 12 import urllib
12 import zipfile 13 import zipfile
13 14
14 JSSHELL_VERSION = "31.5.0" 15 JSSHELL_DIR = "mozilla-esr31"
15 JSSHELL_URL = ("https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly" 16 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 "/2015/02/2015-02-25-00-22-19-%s/jsshell-%%s.zip" % JSSHELL_DIR)
17 18
18 JSSHELL_SUPPORTED_PLATFORMS = { 19 JSSHELL_SUPPORTED_PLATFORMS = {
19 "win32": "win32", 20 "win32": "win32",
20 "linux2": { 21 "linux2": {
21 "i686": "linux-i686", 22 "i686": "linux-i686",
22 "x86_64": "linux-x86_64" 23 "x86_64": "linux-x86_64"
23 }, 24 },
24 "darwin": "mac" 25 "darwin": "mac"
25 } 26 }
26 27
27 def ensureJSShell(): 28 def ensureJSShell():
28 baseDir = os.path.dirname(__file__) 29 baseDir = os.path.dirname(__file__)
29 shell_dir = os.path.join(baseDir, "jsshell-%s" % JSSHELL_VERSION) 30 shell_dir = os.path.join(baseDir, JSSHELL_DIR)
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 31
31 if not os.path.exists(shell_dir): 32 if not os.path.exists(shell_dir):
32 os.makedirs(shell_dir) 33 os.makedirs(shell_dir)
33 if sys.platform == 'win32': 34 if sys.platform == 'win32':
34 path = os.path.join(shell_dir, 'js.exe') 35 path = os.path.join(shell_dir, 'js.exe')
35 else: 36 else:
36 path = os.path.join(shell_dir, 'js') 37 path = os.path.join(shell_dir, 'js')
37 38
38 if os.path.exists(path): 39 if os.path.exists(path):
39 return path 40 return path
40 41
41 try: 42 try:
42 build = JSSHELL_SUPPORTED_PLATFORMS[sys.platform] 43 build = JSSHELL_SUPPORTED_PLATFORMS[sys.platform]
43 if isinstance(build, dict): 44 if isinstance(build, dict):
44 build = build[platform.machine()] 45 build = build[platform.machine()]
45 except KeyError: 46 except KeyError:
46 raise Exception('Platform %s (%s) not supported by JS shell' % ( 47 raise Exception('Platform %s (%s) not supported by JS shell' % (
47 sys.platform, platform.machine() 48 sys.platform, platform.machine()
48 )) 49 ))
49 50
50 data = StringIO(urllib.urlopen(JSSHELL_URL % build).read()) 51 with closing(urllib.urlopen(JSSHELL_URL % build)) as response, \
Sebastian Noack 2015/11/23 12:53:58 While changing this code anyway, mind closing the
kzar 2015/11/23 13:20:21 Done.
51 zip = zipfile.ZipFile(data) 52 zipfile.ZipFile(StringIO(response.read())) as zip:
52 zip.extractall(shell_dir) 53 zip.extractall(shell_dir)
53 zip.close()
54 54
55 if not os.path.exists(path): 55 if not os.path.exists(path):
56 raise Exception('Downloaded package didn\'t contain JS shell executable') 56 raise Exception('Downloaded package didn\'t contain JS shell executable')
57 57
58 try: 58 try:
59 os.chmod(path, 0700) 59 os.chmod(path, 0700)
60 except: 60 except:
61 pass 61 pass
62 62
63 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