| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 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 os | 7 import os |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 _BUILD_ANDROID = os.path.join(os.path.dirname(__file__), os.pardir) | 10 _BUILD_ANDROID = os.path.join(os.path.dirname(__file__), os.pardir) |
| 11 sys.path.append(_BUILD_ANDROID) | 11 sys.path.append(_BUILD_ANDROID) |
| 12 from pylib.constants import host_paths | 12 from pylib.constants import host_paths |
| 13 | 13 |
| 14 sys.path.append(os.path.join(host_paths.DIR_SOURCE_ROOT, 'build')) | 14 sys.path.append(os.path.join(host_paths.DIR_SOURCE_ROOT, 'build')) |
| 15 import find_depot_tools # pylint: disable=import-error,unused-import | 15 import find_depot_tools # pylint: disable=import-error,unused-import |
| 16 import download_from_google_storage | 16 import download_from_google_storage |
| 17 | 17 |
| 18 CURRENT_MILESTONE = '58' | 18 CURRENT_MILESTONE = '58' |
| 19 DEFAULT_BUCKET = 'gs://chromium-android-tools/apks' | 19 DEFAULT_BUCKET = 'gs://chromium-android-tools/apks' |
| 20 DEFAULT_DOWNLOAD_PATH = os.path.join(os.path.dirname(__file__), 'apks') | 20 DEFAULT_DOWNLOAD_PATH = os.path.join(os.path.dirname(__file__), 'apks') |
| 21 DEFAULT_BUILDER = 'Android_Builder' | 21 DEFAULT_BUILDER = 'Android_Builder' |
| 22 DEFAULT_APK = 'MonochromePublic.apk' | 22 DEFAULT_APK = 'MonochromePublic.apk' |
| 23 | 23 |
| 24 | 24 |
| 25 def MaybeDownloadApk(builder, milestone, apk, download_path, bucket): | 25 def MaybeDownloadApk(builder, milestone, apk, download_path, bucket): |
| 26 """Returns path to the downloaded APK or None if not found.""" |
| 26 apk_path = os.path.join(download_path, builder, milestone, apk) | 27 apk_path = os.path.join(download_path, builder, milestone, apk) |
| 27 sha1_path = apk_path + '.sha1' | 28 sha1_path = apk_path + '.sha1' |
| 28 base_url = os.path.join(bucket, builder, milestone) | 29 base_url = os.path.join(bucket, builder, milestone) |
| 29 if os.path.exists(apk_path): | 30 if os.path.exists(apk_path): |
| 30 print '%s already exists' % apk_path | 31 print '%s already exists' % apk_path |
| 32 return apk_path |
| 31 elif not os.path.exists(sha1_path): | 33 elif not os.path.exists(sha1_path): |
| 32 print 'Skipping %s, file not found' % sha1_path | 34 print 'Skipping %s, file not found' % sha1_path |
| 35 return None |
| 33 else: | 36 else: |
| 34 download_from_google_storage.download_from_google_storage( | 37 download_from_google_storage.download_from_google_storage( |
| 35 input_filename=sha1_path, | 38 input_filename=sha1_path, |
| 36 sha1_file=sha1_path, | 39 sha1_file=sha1_path, |
| 37 base_url=base_url, | 40 base_url=base_url, |
| 38 gsutil=download_from_google_storage.Gsutil( | 41 gsutil=download_from_google_storage.Gsutil( |
| 39 download_from_google_storage.GSUTIL_DEFAULT_PATH), | 42 download_from_google_storage.GSUTIL_DEFAULT_PATH), |
| 40 num_threads=1, | 43 num_threads=1, |
| 41 directory=False, | 44 directory=False, |
| 42 recursive=False, | 45 recursive=False, |
| 43 force=False, | 46 force=False, |
| 44 output=apk_path, | 47 output=apk_path, |
| 45 ignore_errors=False, | 48 ignore_errors=False, |
| 46 verbose=True, | 49 verbose=True, |
| 47 auto_platform=False, | 50 auto_platform=False, |
| 48 extract=False) | 51 extract=False) |
| 52 return apk_path |
| 49 | 53 |
| 50 | 54 |
| 51 def main(): | 55 def main(): |
| 52 argparser = argparse.ArgumentParser( | 56 argparser = argparse.ArgumentParser( |
| 53 description='Utility for downloading archived APKs used for measuring ' | 57 description='Utility for downloading archived APKs used for measuring ' |
| 54 'per-milestone patch size growth.', | 58 'per-milestone patch size growth.', |
| 55 formatter_class=argparse.ArgumentDefaultsHelpFormatter) | 59 formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 56 argparser.add_argument('--download-path', default=DEFAULT_DOWNLOAD_PATH, | 60 argparser.add_argument('--download-path', default=DEFAULT_DOWNLOAD_PATH, |
| 57 help='Directory to store downloaded APKs.') | 61 help='Directory to store downloaded APKs.') |
| 58 argparser.add_argument('--milestone', default=CURRENT_MILESTONE, | 62 argparser.add_argument('--milestone', default=CURRENT_MILESTONE, |
| 59 help='Download reference APK for this milestone.') | 63 help='Download reference APK for this milestone.') |
| 60 argparser.add_argument('--apk', default=DEFAULT_APK, help='APK name.') | 64 argparser.add_argument('--apk', default=DEFAULT_APK, help='APK name.') |
| 61 argparser.add_argument('--builder', default=DEFAULT_BUILDER, | 65 argparser.add_argument('--builder', default=DEFAULT_BUILDER, |
| 62 help='Builder name.') | 66 help='Builder name.') |
| 63 argparser.add_argument('--bucket', default=DEFAULT_BUCKET, | 67 argparser.add_argument('--bucket', default=DEFAULT_BUCKET, |
| 64 help='Google storage bucket where APK is stored.') | 68 help='Google storage bucket where APK is stored.') |
| 65 args = argparser.parse_args() | 69 args = argparser.parse_args() |
| 66 MaybeDownloadApk( | 70 MaybeDownloadApk( |
| 67 args.builder, args.milestone, args.apk, args.download_path, args.bucket) | 71 args.builder, args.milestone, args.apk, args.download_path, args.bucket) |
| 68 | 72 |
| 69 | 73 |
| 70 if __name__ == '__main__': | 74 if __name__ == '__main__': |
| 71 sys.exit(main()) | 75 sys.exit(main()) |
| OLD | NEW |