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

Side by Side Diff: utils.py

Issue 29330730: Noissue - Append build name to jsshell directory (Closed)
Patch Set: Created Nov. 24, 2015, 10:31 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 from contextlib import closing 7 from contextlib import closing
8 import os 8 import os
9 import platform 9 import platform
10 from StringIO import StringIO 10 from StringIO import StringIO
11 import sys 11 import sys
12 import urllib 12 import urllib
13 import zipfile 13 import zipfile
14 14
15 JSSHELL_DIR = "mozilla-esr31" 15 JSSHELL_DIR = "mozilla-esr31"
16 JSSHELL_URL = ("https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly" 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) 17 "/2015/02/2015-02-25-00-22-19-%s/jsshell-%%s.zip" % JSSHELL_DIR)
18 18
19 JSSHELL_SUPPORTED_PLATFORMS = { 19 JSSHELL_SUPPORTED_PLATFORMS = {
20 "win32": "win32", 20 "win32": "win32",
21 "linux2": { 21 "linux2": {
22 "i686": "linux-i686", 22 "i686": "linux-i686",
23 "x86_64": "linux-x86_64" 23 "x86_64": "linux-x86_64"
24 }, 24 },
25 "darwin": "mac" 25 "darwin": "mac"
26 } 26 }
27 27
28 def ensureJSShell(): 28 def ensureJSShell():
29 baseDir = os.path.dirname(__file__) 29 baseDir = os.path.dirname(__file__)
30 shell_dir = os.path.join(baseDir, JSSHELL_DIR)
31 30
31 try:
32 build = JSSHELL_SUPPORTED_PLATFORMS[sys.platform]
33 if isinstance(build, dict):
34 build = build[platform.machine()]
35 except KeyError:
36 raise Exception('Platform %s (%s) not supported by JS shell' % (
37 sys.platform, platform.machine()
38 ))
39
40 shell_dir = os.path.join(baseDir, JSSHELL_DIR + "-" + build)
Sebastian Noack 2015/11/24 10:38:43 Nit: "%s-%s" % (JSSHELL_DIR, build)
kzar 2015/11/24 10:43:20 I think it looks cleaner as is. os.path.join(base
Sebastian Noack 2015/11/24 10:52:03 I would generally disagree, if it's only for consi
Wladimir Palant 2015/11/24 11:12:40 I tend to agree with Sebastian here but indeed not
32 if not os.path.exists(shell_dir): 41 if not os.path.exists(shell_dir):
33 os.makedirs(shell_dir) 42 os.makedirs(shell_dir)
34 if sys.platform == 'win32': 43 if sys.platform == 'win32':
35 path = os.path.join(shell_dir, 'js.exe') 44 path = os.path.join(shell_dir, 'js.exe')
36 else: 45 else:
37 path = os.path.join(shell_dir, 'js') 46 path = os.path.join(shell_dir, 'js')
38 47
39 if os.path.exists(path): 48 if os.path.exists(path):
40 return path 49 return path
41 50
42 try:
43 build = JSSHELL_SUPPORTED_PLATFORMS[sys.platform]
44 if isinstance(build, dict):
45 build = build[platform.machine()]
46 except KeyError:
47 raise Exception('Platform %s (%s) not supported by JS shell' % (
48 sys.platform, platform.machine()
49 ))
50
51 with closing(urllib.urlopen(JSSHELL_URL % build)) as response, \ 51 with closing(urllib.urlopen(JSSHELL_URL % build)) as response, \
52 zipfile.ZipFile(StringIO(response.read())) as zip: 52 zipfile.ZipFile(StringIO(response.read())) as zip:
53 zip.extractall(shell_dir) 53 zip.extractall(shell_dir)
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
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