OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Utility script to install APKs from the command line quickly.""" | 7 """Utility script to install APKs from the command line quickly.""" |
8 | 8 |
9 import argparse | 9 import argparse |
10 import glob | 10 import glob |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 dest='build_type', | 46 dest='build_type', |
47 default=os.environ.get('BUILDTYPE', 'Debug'), | 47 default=os.environ.get('BUILDTYPE', 'Debug'), |
48 help='If set, run test suites under out/Debug. ' | 48 help='If set, run test suites under out/Debug. ' |
49 'Default is env var BUILDTYPE or Debug') | 49 'Default is env var BUILDTYPE or Debug') |
50 parser.add_argument('--release', action='store_const', const='Release', | 50 parser.add_argument('--release', action='store_const', const='Release', |
51 dest='build_type', | 51 dest='build_type', |
52 help='If set, run test suites under out/Release. ' | 52 help='If set, run test suites under out/Release. ' |
53 'Default is env var BUILDTYPE or Debug.') | 53 'Default is env var BUILDTYPE or Debug.') |
54 parser.add_argument('-d', '--device', dest='device', | 54 parser.add_argument('-d', '--device', dest='device', |
55 help='Target device for apk to install on.') | 55 help='Target device for apk to install on.') |
56 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') | |
57 parser.add_argument('-v', '--verbose', action='count', | 56 parser.add_argument('-v', '--verbose', action='count', |
58 help='Enable verbose logging.') | 57 help='Enable verbose logging.') |
59 | 58 |
60 args = parser.parse_args() | 59 args = parser.parse_args() |
61 | 60 |
62 run_tests_helper.SetLogLevel(args.verbose) | 61 run_tests_helper.SetLogLevel(args.verbose) |
63 constants.SetBuildType(args.build_type) | 62 constants.SetBuildType(args.build_type) |
64 | 63 |
65 apk = args.apk_path or args.apk_name | 64 apk = args.apk_path or args.apk_name |
66 if not apk.endswith('.apk'): | 65 if not apk.endswith('.apk'): |
67 apk += '.apk' | 66 apk += '.apk' |
68 if not os.path.exists(apk): | 67 if not os.path.exists(apk): |
69 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) | 68 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) |
70 if not os.path.exists(apk): | 69 if not os.path.exists(apk): |
71 parser.error('%s not found.' % apk) | 70 parser.error('%s not found.' % apk) |
72 | 71 |
73 if args.splits: | 72 if args.splits: |
74 splits = [] | 73 splits = [] |
75 base_apk_package = apk_helper.ApkHelper(apk).GetPackageName() | 74 base_apk_package = apk_helper.ApkHelper(apk).GetPackageName() |
76 for split_glob in args.splits: | 75 for split_glob in args.splits: |
77 apks = [f for f in glob.glob(split_glob) if f.endswith('.apk')] | 76 apks = [f for f in glob.glob(split_glob) if f.endswith('.apk')] |
78 if not apks: | 77 if not apks: |
79 logging.warning('No apks matched for %s.' % split_glob) | 78 logging.warning('No apks matched for %s.' % split_glob) |
80 for f in apks: | 79 for f in apks: |
81 helper = apk_helper.ApkHelper(f) | 80 helper = apk_helper.ApkHelper(f) |
82 if (helper.GetPackageName() == base_apk_package | 81 if (helper.GetPackageName() == base_apk_package |
83 and helper.GetSplitName()): | 82 and helper.GetSplitName()): |
84 splits.append(f) | 83 splits.append(f) |
85 | 84 |
86 if args.blacklist_file: | 85 devices = device_utils.DeviceUtils.HealthyDevices() |
87 blacklist = device_blacklist.Blacklist(args.blacklist_file) | |
88 else: | |
89 # TODO(jbudorick): Remove this once the bots are converted. | |
90 blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON) | |
91 | |
92 devices = device_utils.DeviceUtils.HealthyDevices(blacklist) | |
93 | 86 |
94 if args.device: | 87 if args.device: |
95 devices = [d for d in devices if d == args.device] | 88 devices = [d for d in devices if d == args.device] |
96 if not devices: | 89 if not devices: |
97 raise device_errors.DeviceUnreachableError(args.device) | 90 raise device_errors.DeviceUnreachableError(args.device) |
98 elif not devices: | 91 elif not devices: |
99 raise device_errors.NoDevicesError() | 92 raise device_errors.NoDevicesError() |
100 | 93 |
101 def blacklisting_install(device): | 94 def blacklisting_install(device): |
102 try: | 95 try: |
103 if args.splits: | 96 if args.splits: |
104 device.InstallSplitApk(apk, splits, reinstall=args.keep_data) | 97 device.InstallSplitApk(apk, splits, reinstall=args.keep_data) |
105 else: | 98 else: |
106 device.Install(apk, reinstall=args.keep_data) | 99 device.Install(apk, reinstall=args.keep_data) |
107 except device_errors.CommandFailedError: | 100 except device_errors.CommandFailedError: |
108 logging.exception('Failed to install %s', args.apk_name) | 101 logging.exception('Failed to install %s', args.apk_name) |
109 if blacklist: | 102 device_blacklist.ExtendBlacklist([str(device)]) |
110 blacklist.Extend([str(device)]) | 103 logging.warning('Blacklisting %s', str(device)) |
111 logging.warning('Blacklisting %s', str(device)) | |
112 except device_errors.CommandTimeoutError: | 104 except device_errors.CommandTimeoutError: |
113 logging.exception('Timed out while installing %s', args.apk_name) | 105 logging.exception('Timed out while installing %s', args.apk_name) |
114 if blacklist: | 106 device_blacklist.ExtendBlacklist([str(device)]) |
115 blacklist.Extend([str(device)]) | 107 logging.warning('Blacklisting %s', str(device)) |
116 logging.warning('Blacklisting %s', str(device)) | |
117 | 108 |
118 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) | 109 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) |
119 | 110 |
120 | 111 |
121 if __name__ == '__main__': | 112 if __name__ == '__main__': |
122 sys.exit(main()) | 113 sys.exit(main()) |
123 | 114 |
OLD | NEW |