| #!/usr/bin/env python |
| # Copyright 2015 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Tool to download keys needed to sign the official Mojo Shell APK build. |
| """ |
| |
| import argparse |
| import os |
| import subprocess |
| import sys |
| |
| import mopy.gn as gn |
| from mopy.config import Config |
| from mopy.paths import Paths |
| |
| |
| # Google Storage path of the official keystore to download. |
| _KEYSTORE_PATH = "gs://mojo/android/keys/mojo_shell-official.keystore" |
| _KEYSTORE_PWD_PATH = "gs://mojo/android/keys/mojo_shell-official.pwd" |
| |
| |
| def _get_gsutil_exe(): |
| """Get the path to gsutil executable.""" |
| config = Config(target_os=Config.OS_ANDROID, is_debug=False, |
| is_official_build=True) |
| paths = Paths(config) |
| sys.path.insert(0, os.path.join(paths.src_root, "tools")) |
| # pylint: disable=F0401 |
| import find_depot_tools |
| depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
| gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", |
| "gsutil") |
| return gsutil_exe |
| |
| |
| def _download_keystore(args): |
| """Downloads the keystore file on local disk.""" |
| directory_path = args.output[0] |
| if args.verbose: |
| print "Downloading " + _KEYSTORE_PATH + " to " + directory_path |
| gsutil_exe = _get_gsutil_exe() |
| if args.dry_run: |
| print str([gsutil_exe, "cp", _KEYSTORE_PATH, directory_path]) |
| else: |
| subprocess.check_call([gsutil_exe, "cp", _KEYSTORE_PATH, directory_path]) |
| |
| |
| def _output_password(args): |
| """Outputs the keystore password on the standard output.""" |
| # The build system cannot read a file that is generated by a script and |
| # use its content as a variable. It can either 1/ read a file already there |
| # or 2/ put a script output in a variable. Hence the fact that we do not |
| # download the password to a file, but output it on the standard output. |
| gsutil_exe = _get_gsutil_exe() |
| |
| if args.dry_run: |
| print str([gsutil_exe, "cat", _KEYSTORE_PWD_PATH]) |
| else: |
| subprocess.check_call([gsutil_exe, "cat", _KEYSTORE_PWD_PATH], |
| stdout=sys.stdout) |
| |
| |
| def main(): |
| parser = argparse.ArgumentParser( |
| description="Downloads the keystore used to sign official APK builds.") |
| parser.add_argument("-n", "--dry_run", help="Dry run, do not actually "+ |
| "download", action="store_true") |
| parser.add_argument("-v", "--verbose", help="Verbose mode", |
| action="store_true") |
| |
| subparsers = parser.add_subparsers() |
| |
| keystore_file_parser = subparsers.add_parser( |
| "keystore_file", help="Downloads the keystore file") |
| keystore_file_parser.add_argument("output", nargs=1, type=str, |
| help="Output path to save the keystore to") |
| keystore_file_parser.set_defaults(func=_download_keystore) |
| |
| keystore_pwd_parser = subparsers.add_parser( |
| "keystore_password", help="Outputs the keystore password") |
| keystore_pwd_parser.set_defaults(func=_output_password) |
| |
| args = parser.parse_args() |
| args.func(args) |
| |
| |
| return 0 |
| |
| |
| if __name__ == "__main__": |
| sys.exit(main()) |