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

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

Issue 286423002: Make adb_install_apk.py saner for humans. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@android_build_cleanup
Patch Set: Created 6 years, 7 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 | build/android/buildbot/bb_device_steps.py » ('j') | 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 multiprocessing 9 import multiprocessing
10 import optparse 10 import optparse
11 import os 11 import os
12 import sys 12 import sys
13 13
14 from pylib import android_commands 14 from pylib import android_commands
15 from pylib import constants 15 from pylib import constants
16 from pylib.device import device_utils 16 from pylib.device import device_utils
17 from pylib.utils import apk_helper 17 from pylib.utils import apk_helper
18 18
19 19
20 def AddInstallAPKOption(option_parser): 20 def AddInstallAPKOption(option_parser):
21 """Adds apk option used to install the APK to the OptionParser.""" 21 """Adds apk option used to install the APK to the OptionParser."""
22 option_parser.add_option('--apk', 22 option_parser.add_option('--apk',
23 help=('The name of the apk containing the ' 23 help=('DEPRECATED The name of the apk containing the'
24 ' application (with the .apk extension).')) 24 ' application (with the .apk extension).'))
25 option_parser.add_option('--apk_package', 25 option_parser.add_option('--apk_package',
26 help=('The package name used by the apk containing ' 26 help=('The package name used by the apk containing '
27 'the application.')) 27 'the application.'))
28 option_parser.add_option('--keep_data', 28 option_parser.add_option('--keep_data',
29 action='store_true', 29 action='store_true',
30 default=False, 30 default=False,
31 help=('Keep the package data when installing ' 31 help=('Keep the package data when installing '
32 'the application.')) 32 'the application.'))
33 option_parser.add_option('--debug', action='store_const', const='Debug', 33 option_parser.add_option('--debug', action='store_const', const='Debug',
34 dest='build_type', 34 dest='build_type',
35 default=os.environ.get('BUILDTYPE', 'Debug'), 35 default=os.environ.get('BUILDTYPE', 'Debug'),
36 help='If set, run test suites under out/Debug. ' 36 help='If set, run test suites under out/Debug. '
37 'Default is env var BUILDTYPE or Debug') 37 'Default is env var BUILDTYPE or Debug')
38 option_parser.add_option('--release', action='store_const', const='Release', 38 option_parser.add_option('--release', action='store_const', const='Release',
39 dest='build_type', 39 dest='build_type',
40 help='If set, run test suites under out/Release. ' 40 help='If set, run test suites under out/Release. '
41 'Default is env var BUILDTYPE or Debug.') 41 'Default is env var BUILDTYPE or Debug.')
42 42
43 43
44 def ValidateInstallAPKOption(option_parser, options): 44 def ValidateInstallAPKOption(option_parser, options, args):
45 """Validates the apk option and potentially qualifies the path.""" 45 """Validates the apk option and potentially qualifies the path."""
46 if not options.apk: 46 if not options.apk:
47 option_parser.error('--apk is mandatory.') 47 if len(args) > 1:
48 options.apk = args[1]
49 else:
50 option_parser.error('apk target not specified.')
51 return
jbudorick 2014/05/19 15:13:42 nit: OptionParser.error exits, so the return is un
mlamouri (slow - plz ping) 2014/05/20 13:09:05 Oups, forgot about that one. Fixed.
52
53 if not options.apk.endswith('.apk'):
54 options.apk += '.apk'
55
48 if not os.path.exists(options.apk): 56 if not os.path.exists(options.apk):
49 options.apk = os.path.join(constants.GetOutDirectory(), 'apks', 57 options.apk = os.path.join(constants.GetOutDirectory(), 'apks',
50 options.apk) 58 options.apk)
51 59
52 60
53 def _InstallApk(args): 61 def _InstallApk(args):
54 apk_path, apk_package, keep_data, device = args 62 apk_path, apk_package, keep_data, device = args
55 device_utils.DeviceUtils(device=device).old_interface.ManagedInstall( 63 device_utils.DeviceUtils(device=device).old_interface.ManagedInstall(
56 apk_path, keep_data, apk_package) 64 apk_path, keep_data, apk_package)
57 print '----- Installed on %s -----' % device 65 print '----- Installed on %s -----' % device
58 66
59 67
60 def main(argv): 68 def main(argv):
61 parser = optparse.OptionParser() 69 parser = optparse.OptionParser()
70 parser.set_usage("usage: %prog [options] target")
62 AddInstallAPKOption(parser) 71 AddInstallAPKOption(parser)
63 options, args = parser.parse_args(argv) 72 options, args = parser.parse_args(argv)
73
74 if len(args) > 1 and options.apk:
75 parser.error("Appending the apk as argument can't be used with --apk.")
76 elif len(args) > 2:
77 parser.error("Too many arguments.")
78
64 constants.SetBuildType(options.build_type) 79 constants.SetBuildType(options.build_type)
65 ValidateInstallAPKOption(parser, options) 80 ValidateInstallAPKOption(parser, options, args)
66 if len(args) > 1:
67 raise Exception('Error: Unknown argument:', args[1:])
68 81
69 devices = android_commands.GetAttachedDevices() 82 devices = android_commands.GetAttachedDevices()
70 if not devices: 83 if not devices:
71 raise Exception('Error: no connected devices') 84 raise Exception('Error: no connected devices')
72 85
73 if not options.apk_package: 86 if not options.apk_package:
74 options.apk_package = apk_helper.GetPackageName(options.apk) 87 options.apk_package = apk_helper.GetPackageName(options.apk)
75 88
76 pool = multiprocessing.Pool(len(devices)) 89 pool = multiprocessing.Pool(len(devices))
77 # Send a tuple (apk_path, apk_package, device) per device. 90 # Send a tuple (apk_path, apk_package, device) per device.
78 pool.map(_InstallApk, zip([options.apk] * len(devices), 91 pool.map(_InstallApk, zip([options.apk] * len(devices),
79 [options.apk_package] * len(devices), 92 [options.apk_package] * len(devices),
80 [options.keep_data] * len(devices), 93 [options.keep_data] * len(devices),
81 devices)) 94 devices))
82 95
83 96
84 if __name__ == '__main__': 97 if __name__ == '__main__':
85 sys.exit(main(sys.argv)) 98 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | build/android/buildbot/bb_device_steps.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698