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

Side by Side Diff: utils.py

Issue 29350244: Issue 4374 - Made Python code part of jshydra comply with our coding practices (Closed)
Patch Set: Created Aug. 28, 2016, 10:42 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 | « tox.ini ('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 # This Source Code is subject to the terms of the Mozilla Public License 1 # This Source Code is subject to the terms of the Mozilla Public License
2 # version 2.0 (the "License"). You can obtain a copy of the License at 2 # version 2.0 (the "License"). You can obtain a copy of the License at
3 # http://mozilla.org/MPL/2.0/. 3 # http://mozilla.org/MPL/2.0/.
4 4
5 import os 5 import os
6 import platform 6 import platform
7 import io 7 import io
8 import zipfile 8 import zipfile
9 9
10 try: 10 try:
(...skipping 13 matching lines...) Expand all
24 JSSHELL_SUPPORTED_PLATFORMS = { 24 JSSHELL_SUPPORTED_PLATFORMS = {
25 'Windows': 'win32', 25 'Windows': 'win32',
26 'Linux': { 26 'Linux': {
27 'i686': 'linux-i686', 27 'i686': 'linux-i686',
28 'x86_64': 'linux-x86_64' 28 'x86_64': 'linux-x86_64'
29 }, 29 },
30 'Darwin': 'mac' 30 'Darwin': 'mac'
31 } 31 }
32 32
33 33
34 def ensureJSShell(): 34 def ensure_jsshell():
35 path = os.environ.get('SPIDERMONKEY_BINARY') 35 path = os.environ.get('SPIDERMONKEY_BINARY')
36 if path and os.path.isfile(path): 36 if path and os.path.isfile(path):
37 return path 37 return path
38 38
39 baseDir = os.path.dirname(__file__)
40 system = platform.system() 39 system = platform.system()
41
42 try: 40 try:
43 build = JSSHELL_SUPPORTED_PLATFORMS[system] 41 build = JSSHELL_SUPPORTED_PLATFORMS[system]
44 if isinstance(build, dict): 42 if isinstance(build, dict):
45 build = build[platform.machine()] 43 build = build[platform.machine()]
46 except KeyError: 44 except KeyError:
47 raise Exception('Platform {} ({}) not supported by JS shell'.format( 45 raise Exception('Platform {} ({}) not supported by JS shell'.format(
48 system, platform.machine() 46 system, platform.machine()
49 )) 47 ))
50 48
51 shell_dir = os.path.join(baseDir, JSSHELL_DIR + "-" + build) 49 shell_dir = os.path.join(os.path.dirname(__file__),
50 '{}-{}'.format(JSSHELL_DIR, build))
52 if not os.path.exists(shell_dir): 51 if not os.path.exists(shell_dir):
53 os.makedirs(shell_dir) 52 os.makedirs(shell_dir)
54 if system == 'Windows': 53 if system == 'Windows':
55 path = os.path.join(shell_dir, 'js.exe') 54 path = os.path.join(shell_dir, 'js.exe')
56 else: 55 else:
57 path = os.path.join(shell_dir, 'js') 56 path = os.path.join(shell_dir, 'js')
58 57
59 if os.path.exists(path): 58 if os.path.exists(path):
60 return path 59 return path
61 60
62 with urlopen(JSSHELL_URL.format(build)) as response: 61 with urlopen(JSSHELL_URL.format(build)) as response:
63 data = response.read() 62 data = response.read()
64 63
65 with zipfile.ZipFile(io.BytesIO(data)) as archive: 64 with zipfile.ZipFile(io.BytesIO(data)) as archive:
66 archive.extractall(shell_dir) 65 archive.extractall(shell_dir)
67 66
68 if not os.path.exists(path): 67 if not os.path.exists(path):
69 raise Exception('Downloaded package didn\'t contain JS shell executable' ) 68 raise Exception("Downloaded package doesn't contain JS shell")
70 69
71 try: 70 try:
72 os.chmod(path, 0o700) 71 os.chmod(path, 0o700)
73 except: 72 except:
74 pass 73 pass
75 74
76 return path 75 return path
OLDNEW
« no previous file with comments | « tox.ini ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld