Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: mojo/devtools/common/devtoolslib/download.py

Issue 1844943004: devtools: download shell binaries and set origin when run w/ --mojo-version. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/devtools/common/.gitignore ('k') | mojo/devtools/common/devtoolslib/paths.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
qsr 2016/03/31 14:39:15 This is so last year.
ppi 2016/03/31 15:08:51 Fixed.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import os
6 import subprocess
7 import sys
8 import tempfile
9 import urllib2
10 import zipfile
11
12 from devtoolslib import paths
13
14
15 _SHELL_FILE_NAME = {
16 'linux-x64': 'mojo_shell',
17 'android-arm': 'MojoShell.apk'
18 }
19
20
21 def _get_artifacts_to_download(mojo_version, platform, verbose):
22 """Returns a list of tuples of (gs_path, file_name) to be downloaded."""
23 artifacts = []
24 shell_gs_path = ('gs://mojo/shell/%s/%s.zip' % (mojo_version, platform))
25 artifacts.append(
26 (shell_gs_path, _SHELL_FILE_NAME[platform])
27 )
28 if platform == 'linux-x64':
29 network_service_version_url = (
30 'https://raw.githubusercontent.com/domokit/mojo/' +
31 mojo_version + '/mojo/public/tools/NETWORK_SERVICE_VERSION')
32 network_service_version = (
33 urllib2.urlopen(network_service_version_url).read().strip())
34 if verbose:
35 print('Looked up the network service version for mojo at %s as: %s ' % (
36 mojo_version, network_service_version))
37
38 network_service_gs_path = (
39 'gs://mojo/network_service/%s/%s/network_service.mojo.zip' %
40 (network_service_version, platform))
41 artifacts.append(
42 (network_service_gs_path, 'network_service.mojo')
43 )
44 return artifacts
45
46
47 def _download_from_gs(gs_path, output_path, depot_tools_path, verbose):
48 """Downloads the file at the given gs_path using depot_tools."""
49 # We're downloading from a public bucket which does not need authentication,
50 # but the user might have busted credential files somewhere such as ~/.boto
51 # that the gsutil script will try (and fail) to use. Setting these
52 # environment variables convinces gsutil not to attempt to use these, but
53 # also generates a useless warning about failing to load the file. We want
54 # to discard this warning but still preserve all output in the case of an
55 # actual failure. So, we run the script and capture all output and then
56 # throw the output away if the script succeeds (return code 0).
qsr 2016/03/31 14:39:15 I do not see the code to do any of this. What am I
ppi 2016/03/31 15:08:51 Redacted. This was carried over from mojo/public/t
57 env = os.environ.copy()
58 env['AWS_CREDENTIAL_FILE'] = ""
59 env['BOTO_CONFIG'] = ""
60
61 gsutil_exe = os.path.join(depot_tools_path, 'third_party', 'gsutil', 'gsutil')
62 if verbose:
63 print('Fetching ' + gs_path)
64
65 try:
66 subprocess.check_output(
67 [gsutil_exe,
68 '--bypass_prodaccess',
69 'cp',
70 gs_path,
71 output_path],
72 stderr=subprocess.STDOUT,
73 env=env)
74 except subprocess.CalledProcessError as e:
75 print e.output
76 sys.exit(1)
77
78
79 def _extract_file(archive_path, file_name, output_dir):
80 with zipfile.ZipFile(archive_path) as z:
81 zi = z.getinfo(file_name)
82 mode = zi.external_attr >> 16
83 z.extract(zi, output_dir)
84 os.chmod(os.path.join(output_dir, file_name), mode)
85
86
87 def download_shell(mojo_version, platform, root_output_dir, verbose):
88 """Downloads the shell (along with corresponding artifacts if needed) at the
89 given version.
90 """
91 depot_tools_path = paths.find_depot_tools()
92 artifacts = _get_artifacts_to_download(mojo_version, platform, verbose)
93 output_dir = os.path.join(root_output_dir, mojo_version, platform)
94
95 for (gs_path, file_name) in artifacts:
96 if os.path.isfile(os.path.join(output_dir, file_name)):
97 continue
98
99 with tempfile.NamedTemporaryFile() as temp_zip_file:
100 _download_from_gs(gs_path, temp_zip_file.name, depot_tools_path, verbose)
101 _extract_file(temp_zip_file.name, file_name, output_dir)
102
103 return os.path.join(output_dir, _SHELL_FILE_NAME[platform])
OLDNEW
« no previous file with comments | « mojo/devtools/common/.gitignore ('k') | mojo/devtools/common/devtoolslib/paths.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698