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.') |
56 parser.add_argument('-v', '--verbose', action='count', | 57 parser.add_argument('-v', '--verbose', action='count', |
57 help='Enable verbose logging.') | 58 help='Enable verbose logging.') |
58 | 59 |
59 args = parser.parse_args() | 60 args = parser.parse_args() |
60 | 61 |
61 run_tests_helper.SetLogLevel(args.verbose) | 62 run_tests_helper.SetLogLevel(args.verbose) |
62 constants.SetBuildType(args.build_type) | 63 constants.SetBuildType(args.build_type) |
63 | 64 |
64 apk = args.apk_path or args.apk_name | 65 apk = args.apk_path or args.apk_name |
65 if not apk.endswith('.apk'): | 66 if not apk.endswith('.apk'): |
66 apk += '.apk' | 67 apk += '.apk' |
67 if not os.path.exists(apk): | 68 if not os.path.exists(apk): |
68 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) | 69 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) |
69 if not os.path.exists(apk): | 70 if not os.path.exists(apk): |
70 parser.error('%s not found.' % apk) | 71 parser.error('%s not found.' % apk) |
71 | 72 |
72 if args.splits: | 73 if args.splits: |
73 splits = [] | 74 splits = [] |
74 base_apk_package = apk_helper.ApkHelper(apk).GetPackageName() | 75 base_apk_package = apk_helper.ApkHelper(apk).GetPackageName() |
75 for split_glob in args.splits: | 76 for split_glob in args.splits: |
76 apks = [f for f in glob.glob(split_glob) if f.endswith('.apk')] | 77 apks = [f for f in glob.glob(split_glob) if f.endswith('.apk')] |
77 if not apks: | 78 if not apks: |
78 logging.warning('No apks matched for %s.' % split_glob) | 79 logging.warning('No apks matched for %s.' % split_glob) |
79 for f in apks: | 80 for f in apks: |
80 helper = apk_helper.ApkHelper(f) | 81 helper = apk_helper.ApkHelper(f) |
81 if (helper.GetPackageName() == base_apk_package | 82 if (helper.GetPackageName() == base_apk_package |
82 and helper.GetSplitName()): | 83 and helper.GetSplitName()): |
83 splits.append(f) | 84 splits.append(f) |
84 | 85 |
85 devices = device_utils.DeviceUtils.HealthyDevices() | 86 if args.blacklist_file: |
| 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) |
86 | 93 |
87 if args.device: | 94 if args.device: |
88 devices = [d for d in devices if d == args.device] | 95 devices = [d for d in devices if d == args.device] |
89 if not devices: | 96 if not devices: |
90 raise device_errors.DeviceUnreachableError(args.device) | 97 raise device_errors.DeviceUnreachableError(args.device) |
91 elif not devices: | 98 elif not devices: |
92 raise device_errors.NoDevicesError() | 99 raise device_errors.NoDevicesError() |
93 | 100 |
94 def blacklisting_install(device): | 101 def blacklisting_install(device): |
95 try: | 102 try: |
96 if args.splits: | 103 if args.splits: |
97 device.InstallSplitApk(apk, splits, reinstall=args.keep_data) | 104 device.InstallSplitApk(apk, splits, reinstall=args.keep_data) |
98 else: | 105 else: |
99 device.Install(apk, reinstall=args.keep_data) | 106 device.Install(apk, reinstall=args.keep_data) |
100 except device_errors.CommandFailedError: | 107 except device_errors.CommandFailedError: |
101 logging.exception('Failed to install %s', args.apk_name) | 108 logging.exception('Failed to install %s', args.apk_name) |
102 device_blacklist.ExtendBlacklist([str(device)]) | 109 if blacklist: |
103 logging.warning('Blacklisting %s', str(device)) | 110 blacklist.Extend([str(device)]) |
| 111 logging.warning('Blacklisting %s', str(device)) |
104 except device_errors.CommandTimeoutError: | 112 except device_errors.CommandTimeoutError: |
105 logging.exception('Timed out while installing %s', args.apk_name) | 113 logging.exception('Timed out while installing %s', args.apk_name) |
106 device_blacklist.ExtendBlacklist([str(device)]) | 114 if blacklist: |
107 logging.warning('Blacklisting %s', str(device)) | 115 blacklist.Extend([str(device)]) |
| 116 logging.warning('Blacklisting %s', str(device)) |
108 | 117 |
109 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) | 118 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) |
110 | 119 |
111 | 120 |
112 if __name__ == '__main__': | 121 if __name__ == '__main__': |
113 sys.exit(main()) | 122 sys.exit(main()) |
114 | 123 |
OLD | NEW |