OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 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. |
| 53 env = os.environ.copy() |
| 54 env['AWS_CREDENTIAL_FILE'] = "" |
| 55 env['BOTO_CONFIG'] = "" |
| 56 |
| 57 gsutil_exe = os.path.join(depot_tools_path, 'third_party', 'gsutil', 'gsutil') |
| 58 if verbose: |
| 59 print('Fetching ' + gs_path) |
| 60 |
| 61 try: |
| 62 subprocess.check_output( |
| 63 [gsutil_exe, |
| 64 '--bypass_prodaccess', |
| 65 'cp', |
| 66 gs_path, |
| 67 output_path], |
| 68 stderr=subprocess.STDOUT, |
| 69 env=env) |
| 70 except subprocess.CalledProcessError as e: |
| 71 print e.output |
| 72 sys.exit(1) |
| 73 |
| 74 |
| 75 def _extract_file(archive_path, file_name, output_dir): |
| 76 with zipfile.ZipFile(archive_path) as z: |
| 77 zi = z.getinfo(file_name) |
| 78 mode = zi.external_attr >> 16 |
| 79 z.extract(zi, output_dir) |
| 80 os.chmod(os.path.join(output_dir, file_name), mode) |
| 81 |
| 82 |
| 83 def download_shell(mojo_version, platform, root_output_dir, verbose): |
| 84 """Downloads the shell (along with corresponding artifacts if needed) at the |
| 85 given version. |
| 86 """ |
| 87 depot_tools_path = paths.find_depot_tools() |
| 88 artifacts = _get_artifacts_to_download(mojo_version, platform, verbose) |
| 89 output_dir = os.path.join(root_output_dir, mojo_version, platform) |
| 90 |
| 91 for (gs_path, file_name) in artifacts: |
| 92 if os.path.isfile(os.path.join(output_dir, file_name)): |
| 93 continue |
| 94 |
| 95 with tempfile.NamedTemporaryFile() as temp_zip_file: |
| 96 _download_from_gs(gs_path, temp_zip_file.name, depot_tools_path, verbose) |
| 97 _extract_file(temp_zip_file.name, file_name, output_dir) |
| 98 |
| 99 return os.path.join(output_dir, _SHELL_FILE_NAME[platform]) |
OLD | NEW |