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: Rebased and fixed typo Created Aug. 30, 2016, 12:01 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
« autotest.py ('K') | « 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
(Empty)
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
3 # http://mozilla.org/MPL/2.0/.
4
5 import os
6 import platform
7 import io
8 import zipfile
9
10 try:
11 from urllib.request import urlopen
12 except ImportError:
13 import urllib2
14 import contextlib
15
16 def urlopen(*args, **kwargs):
17 return contextlib.closing(urllib2.urlopen(*args, **kwargs))
18
19 JSSHELL_DIR = 'mozilla-esr31'
20 JSSHELL_URL = ('https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly'
21 '/2015/02/2015-02-25-00-22-19-{}'
22 '/jsshell-{{}}.zip'.format(JSSHELL_DIR))
23
24 JSSHELL_SUPPORTED_PLATFORMS = {
25 'Windows': 'win32',
26 'Linux': {
27 'i686': 'linux-i686',
28 'x86_64': 'linux-x86_64'
29 },
30 'Darwin': 'mac'
31 }
32
33
34 def ensureJSShell():
35 path = os.environ.get('SPIDERMONKEY_BINARY')
36 if path and os.path.isfile(path):
37 return path
38
39 baseDir = os.path.dirname(__file__)
40 system = platform.system()
41
42 try:
43 build = JSSHELL_SUPPORTED_PLATFORMS[system]
44 if isinstance(build, dict):
45 build = build[platform.machine()]
46 except KeyError:
47 raise Exception('Platform {} ({}) not supported by JS shell'.format(
48 system, platform.machine()
49 ))
50
51 shell_dir = os.path.join(baseDir, JSSHELL_DIR + "-" + build)
52 if not os.path.exists(shell_dir):
53 os.makedirs(shell_dir)
54 if system == 'Windows':
55 path = os.path.join(shell_dir, 'js.exe')
56 else:
57 path = os.path.join(shell_dir, 'js')
58
59 if os.path.exists(path):
60 return path
61
62 with urlopen(JSSHELL_URL.format(build)) as response:
63 data = response.read()
64
65 with zipfile.ZipFile(io.BytesIO(data)) as archive:
66 archive.extractall(shell_dir)
67
68 if not os.path.exists(path):
69 raise Exception('Downloaded package didn\'t contain JS shell executable' )
70
71 try:
72 os.chmod(path, 0o700)
73 except:
74 pass
75
76 return path
OLDNEW
« autotest.py ('K') | « tox.ini ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld