| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import argparse | 6 import argparse |
| 7 import gs |
| 7 import os | 8 import os |
| 8 import subprocess | 9 import subprocess |
| 9 import sys | 10 import sys |
| 10 import tempfile | 11 import tempfile |
| 11 import zipfile | 12 import zipfile |
| 12 | 13 |
| 13 BINARY_FOR_PLATFORM = { | 14 BINARY_FOR_PLATFORM = { |
| 14 "linux-x64" : "mojo_shell", | 15 "linux-x64" : "mojo_shell", |
| 15 "android-arm" : "MojoShell.apk" | 16 "android-arm" : "MojoShell.apk" |
| 16 } | 17 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 40 | 41 |
| 41 for platform in ["linux-x64", "android-arm"]: | 42 for platform in ["linux-x64", "android-arm"]: |
| 42 download_version_for_platform(version, platform, tools_directory) | 43 download_version_for_platform(version, platform, tools_directory) |
| 43 | 44 |
| 44 with open(stamp_path, 'w') as stamp_file: | 45 with open(stamp_path, 'w') as stamp_file: |
| 45 stamp_file.write(version) | 46 stamp_file.write(version) |
| 46 return 0 | 47 return 0 |
| 47 | 48 |
| 48 def download_version_for_platform(version, platform, tools_directory): | 49 def download_version_for_platform(version, platform, tools_directory): |
| 49 find_depot_tools_path = os.path.join(CURRENT_PATH, tools_directory) | 50 find_depot_tools_path = os.path.join(CURRENT_PATH, tools_directory) |
| 50 sys.path.insert(0, find_depot_tools_path) | |
| 51 # pylint: disable=F0401 | |
| 52 import find_depot_tools | |
| 53 | 51 |
| 54 basename = platform + ".zip" | 52 basename = platform + ".zip" |
| 55 gs_path = "gs://mojo/shell/" + version + "/" + basename | 53 gs_path = "gs://mojo/shell/" + version + "/" + basename |
| 56 | 54 |
| 57 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | |
| 58 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") | |
| 59 | |
| 60 with tempfile.NamedTemporaryFile() as temp_zip_file: | 55 with tempfile.NamedTemporaryFile() as temp_zip_file: |
| 61 # We're downloading from a public bucket which does not need authentication, | 56 gs.download_from_public_bucket(gs_path, temp_zip_file.name, |
| 62 # but the user might have busted credential files somewhere such as ~/.boto | 57 find_depot_tools_path) |
| 63 # that the gsutil script will try (and fail) to use. Setting these | |
| 64 # environment variables convinces gsutil not to attempt to use these, but | |
| 65 # also generates a useless warning about failing to load the file. We want | |
| 66 # to discard this warning but still preserve all output in the case of an | |
| 67 # actual failure. So, we run the script and capture all output and then | |
| 68 # throw the output away if the script succeeds (return code 0). | |
| 69 env = os.environ.copy() | |
| 70 env["AWS_CREDENTIAL_FILE"] = "" | |
| 71 env["BOTO_CONFIG"] = "" | |
| 72 try: | |
| 73 subprocess.check_output( | |
| 74 [gsutil_exe, | |
| 75 "--bypass_prodaccess", | |
| 76 "cp", | |
| 77 gs_path, | |
| 78 temp_zip_file.name], | |
| 79 stderr=subprocess.STDOUT, | |
| 80 env=env) | |
| 81 except subprocess.CalledProcessError as e: | |
| 82 print e.output | |
| 83 sys.exit(1) | |
| 84 | |
| 85 binary_name = BINARY_FOR_PLATFORM[platform] | 58 binary_name = BINARY_FOR_PLATFORM[platform] |
| 86 output_dir = os.path.join(PREBUILT_FILE_PATH, platform) | 59 output_dir = os.path.join(PREBUILT_FILE_PATH, platform) |
| 87 with zipfile.ZipFile(temp_zip_file.name) as z: | 60 with zipfile.ZipFile(temp_zip_file.name) as z: |
| 88 zi = z.getinfo(binary_name) | 61 zi = z.getinfo(binary_name) |
| 89 mode = zi.external_attr >> 16 | 62 mode = zi.external_attr >> 16 |
| 90 z.extract(zi, output_dir) | 63 z.extract(zi, output_dir) |
| 91 os.chmod(os.path.join(output_dir, binary_name), mode) | 64 os.chmod(os.path.join(output_dir, binary_name), mode) |
| 92 | 65 |
| 93 | 66 |
| 94 def main(): | 67 def main(): |
| 95 parser = argparse.ArgumentParser(description="Download mojo_shell binaries " | 68 parser = argparse.ArgumentParser(description="Download mojo_shell binaries " |
| 96 "from google storage") | 69 "from google storage") |
| 97 parser.add_argument("--tools-directory", | 70 parser.add_argument("--tools-directory", |
| 98 dest="tools_directory", | 71 dest="tools_directory", |
| 99 metavar="<tools-directory>", | 72 metavar="<tools-directory>", |
| 100 type=str, | 73 type=str, |
| 101 help="Path to the directory containing" | 74 help="Path to the directory containing" |
| 102 " find_depot_tools.py, specified as a relative path" | 75 " find_depot_tools.py, specified as a relative path" |
| 103 " from the location of this file.") | 76 " from the location of this file.") |
| 104 args = parser.parse_args() | 77 args = parser.parse_args() |
| 105 if not args.tools_directory: | 78 if not args.tools_directory: |
| 106 print "Must specify --tools_directory; please see help message." | 79 print "Must specify --tools-directory; please see help message." |
| 107 sys.exit(1) | 80 sys.exit(1) |
| 108 return download(args.tools_directory) | 81 return download(args.tools_directory) |
| 109 | 82 |
| 110 if __name__ == "__main__": | 83 if __name__ == "__main__": |
| 111 sys.exit(main()) | 84 sys.exit(main()) |
| OLD | NEW |