Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: build/android/adb_install_apk.py

Issue 321403002: Add option device in install apk script (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 optparse 9 import optparse
10 import os 10 import os
(...skipping 20 matching lines...) Expand all
31 'the application.')) 31 'the application.'))
32 option_parser.add_option('--debug', action='store_const', const='Debug', 32 option_parser.add_option('--debug', action='store_const', const='Debug',
33 dest='build_type', 33 dest='build_type',
34 default=os.environ.get('BUILDTYPE', 'Debug'), 34 default=os.environ.get('BUILDTYPE', 'Debug'),
35 help='If set, run test suites under out/Debug. ' 35 help='If set, run test suites under out/Debug. '
36 'Default is env var BUILDTYPE or Debug') 36 'Default is env var BUILDTYPE or Debug')
37 option_parser.add_option('--release', action='store_const', const='Release', 37 option_parser.add_option('--release', action='store_const', const='Release',
38 dest='build_type', 38 dest='build_type',
39 help='If set, run test suites under out/Release. ' 39 help='If set, run test suites under out/Release. '
40 'Default is env var BUILDTYPE or Debug.') 40 'Default is env var BUILDTYPE or Debug.')
41 option_parser.add_option('-d', '--device', dest='device',
42 help=('Target device for apk to install on.'))
41 43
42 44
43 def ValidateInstallAPKOption(option_parser, options): 45 def ValidateInstallAPKOption(option_parser, options):
44 """Validates the apk option and potentially qualifies the path.""" 46 """Validates the apk option and potentially qualifies the path."""
45 if not options.apk: 47 if not options.apk:
46 option_parser.error('--apk is mandatory.') 48 option_parser.error('--apk is mandatory.')
47 if not os.path.exists(options.apk): 49 if not os.path.exists(options.apk):
48 options.apk = os.path.join(constants.GetOutDirectory(), 'apks', 50 options.apk = os.path.join(constants.GetOutDirectory(), 'apks',
49 options.apk) 51 options.apk)
50 52
51 53
54 def _GetAttachedDevices(device=None):
mlamouri (slow - plz ping) 2014/06/11 09:07:21 I would call the method GetTargetDevices() instead
mlamouri (slow - plz ping) 2014/06/11 09:07:21 It seems that the _Foo() convention isn't used in
55 """Get all attached devices.
56
57 Args:
58 device: Name of a specific device to use.
59
60 Returns:
61 A list of attached devices.
62 """
63 attached_devices = []
64
65 attached_devices = android_commands.GetAttachedDevices()
66 if device:
67 assert device in attached_devices, (
mlamouri (slow - plz ping) 2014/06/11 09:07:21 It seems that we use |raise Exception('Error: ...'
68 'Did not find device %s among attached device. Attached devices: %s'
69 % (device, ', '.join(attached_devices)))
70 attached_devices = [device]
71
72 assert attached_devices, 'No devices attached.'
73
74 return sorted(attached_devices)
75
76
52 def main(argv): 77 def main(argv):
53 parser = optparse.OptionParser() 78 parser = optparse.OptionParser()
54 AddInstallAPKOption(parser) 79 AddInstallAPKOption(parser)
55 options, args = parser.parse_args(argv) 80 options, args = parser.parse_args(argv)
56 constants.SetBuildType(options.build_type) 81 constants.SetBuildType(options.build_type)
57 ValidateInstallAPKOption(parser, options) 82 ValidateInstallAPKOption(parser, options)
58 if len(args) > 1: 83 if len(args) > 1:
59 raise Exception('Error: Unknown argument:', args[1:]) 84 raise Exception('Error: Unknown argument:', args[1:])
60 85
61 devices = android_commands.GetAttachedDevices() 86 devices = _GetAttachedDevices(options.device)
jbudorick 2014/06/11 14:32:00 I'd much rather see something like this both here
62 if not devices: 87 if not devices:
63 raise Exception('Error: no connected devices') 88 raise Exception('Error: no connected devices')
64 89
65 if not options.apk_package: 90 if not options.apk_package:
66 options.apk_package = apk_helper.GetPackageName(options.apk) 91 options.apk_package = apk_helper.GetPackageName(options.apk)
67 92
68 device_utils.DeviceUtils.parallel(devices).old_interface.ManagedInstall( 93 device_utils.DeviceUtils.parallel(devices).old_interface.ManagedInstall(
69 options.apk, options.keep_data, options.apk_package).pFinish(None) 94 options.apk, options.keep_data, options.apk_package).pFinish(None)
70 95
71 96
72 if __name__ == '__main__': 97 if __name__ == '__main__':
73 sys.exit(main(sys.argv)) 98 sys.exit(main(sys.argv))
74 99
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698