Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
|
vtl
2015/02/11 21:52:09
Delete this.
blundell
2015/02/11 22:22:01
Done.
| |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 os | 6 import os |
| 7 import subprocess | 7 import subprocess |
| 8 import sys | 8 import sys |
| 9 import find_depot_tools | |
| 10 | 9 |
| 11 def download_from_public_bucket(gs_path, output_path): | 10 def download_from_public_bucket(gs_path, output_path, find_depot_tools_path): |
| 11 sys.path.insert(0, find_depot_tools_path) | |
|
vtl
2015/02/11 21:52:09
This function having a permanent side effect on sy
blundell
2015/02/11 22:22:01
Sneakily, find_depot_tools.add_depot_tools_to_path
| |
| 12 # pylint: disable=F0401 | |
| 13 import find_depot_tools | |
| 12 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | 14 depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
| 13 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") | 15 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") |
| 14 | 16 |
| 15 # We're downloading from a public bucket which does not need authentication, | 17 # We're downloading from a public bucket which does not need authentication, |
| 16 # but the user might have busted credential files somewhere such as ~/.boto | 18 # but the user might have busted credential files somewhere such as ~/.boto |
| 17 # that the gsutil script will try (and fail) to use. Setting these | 19 # that the gsutil script will try (and fail) to use. Setting these |
| 18 # environment variables convinces gsutil not to attempt to use these, but | 20 # environment variables convinces gsutil not to attempt to use these, but |
| 19 # also generates a useless warning about failing to load the file. We want | 21 # also generates a useless warning about failing to load the file. We want |
| 20 # to discard this warning but still preserve all output in the case of an | 22 # to discard this warning but still preserve all output in the case of an |
| 21 # actual failure. So, we run the script and capture all output and then | 23 # actual failure. So, we run the script and capture all output and then |
| 22 # throw the output away if the script succeeds (return code 0). | 24 # throw the output away if the script succeeds (return code 0). |
| 23 env = os.environ.copy() | 25 env = os.environ.copy() |
| 24 env["AWS_CREDENTIAL_FILE"] = "" | 26 env["AWS_CREDENTIAL_FILE"] = "" |
| 25 env["BOTO_CONFIG"] = "" | 27 env["BOTO_CONFIG"] = "" |
| 26 try: | 28 try: |
| 27 subprocess.check_output( | 29 subprocess.check_output( |
| 28 [gsutil_exe, | 30 [gsutil_exe, |
| 29 "--bypass_prodaccess", | 31 "--bypass_prodaccess", |
| 30 "cp", | 32 "cp", |
| 31 gs_path, | 33 gs_path, |
| 32 output_path], | 34 output_path], |
| 33 stderr=subprocess.STDOUT, | 35 stderr=subprocess.STDOUT, |
| 34 env=env) | 36 env=env) |
| 35 except subprocess.CalledProcessError as e: | 37 except subprocess.CalledProcessError as e: |
| 36 print e.output | 38 print e.output |
| 37 sys.exit(1) | 39 sys.exit(1) |
| OLD | NEW |