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

Side by Side Diff: utils.py

Issue 29340497: Noissue - Refactor code downloading and unpacking jsshell for better readability (Closed)
Patch Set: Created April 18, 2016, 12:34 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 | « 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
(...skipping 30 matching lines...) Expand all
41 shell_dir = os.path.join(baseDir, JSSHELL_DIR + "-" + build) 41 shell_dir = os.path.join(baseDir, JSSHELL_DIR + "-" + build)
42 if not os.path.exists(shell_dir): 42 if not os.path.exists(shell_dir):
43 os.makedirs(shell_dir) 43 os.makedirs(shell_dir)
44 if sys.platform == 'win32': 44 if sys.platform == 'win32':
45 path = os.path.join(shell_dir, 'js.exe') 45 path = os.path.join(shell_dir, 'js.exe')
46 else: 46 else:
47 path = os.path.join(shell_dir, 'js') 47 path = os.path.join(shell_dir, 'js')
48 48
49 if os.path.exists(path): 49 if os.path.exists(path):
50 return path 50 return path
51
52 with closing(urllib.urlopen(JSSHELL_URL % build)) as response:
53 data = response.read()
51 54
52 with closing(urllib.urlopen(JSSHELL_URL % build)) as response, \ 55 with zipfile.ZipFile(StringIO(data)) as zip:
53 zipfile.ZipFile(StringIO(response.read())) as zip:
54 zip.extractall(shell_dir) 56 zip.extractall(shell_dir)
55 57
56 if not os.path.exists(path): 58 if not os.path.exists(path):
57 raise Exception('Downloaded package didn\'t contain JS shell executable' ) 59 raise Exception('Downloaded package didn\'t contain JS shell executable' )
58 60
59 try: 61 try:
60 os.chmod(path, 0700) 62 os.chmod(path, 0700)
61 except: 63 except:
62 pass 64 pass
63 65
64 return path 66 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