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

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 | 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 multiprocessing 9 import multiprocessing
10 import optparse 10 import optparse
(...skipping 19 matching lines...) Expand all
30 dest='build_type', 30 dest='build_type',
31 help='If set, run test suites under out/Release. ' 31 help='If set, run test suites under out/Release. '
32 'Default is env var BUILDTYPE or Debug.') 32 'Default is env var BUILDTYPE or Debug.')
33 33
34 34
35 def AddInstallAPKOption(option_parser): 35 def AddInstallAPKOption(option_parser):
36 """Adds apk option used to install the APK to the OptionParser.""" 36 """Adds apk option used to install the APK to the OptionParser."""
37 AddBuildTypeOption(option_parser) 37 AddBuildTypeOption(option_parser)
38 38
39 option_parser.add_option('--apk', 39 option_parser.add_option('--apk',
40 help=('The name of the apk containing the ' 40 help=('DEPRECATED The name of the apk containing the'
41 ' application (with the .apk extension).')) 41 ' application (with the .apk extension).'))
42 option_parser.add_option('--apk_package', 42 option_parser.add_option('--apk_package',
43 help=('The package name used by the apk containing ' 43 help=('The package name used by the apk containing '
44 'the application.')) 44 'the application.'))
45 option_parser.add_option('--keep_data', 45 option_parser.add_option('--keep_data',
46 action='store_true', 46 action='store_true',
47 default=False, 47 default=False,
48 help=('Keep the package data when installing ' 48 help=('Keep the package data when installing '
49 'the application.')) 49 'the application.'))
50 50
51 51
52 def ValidateInstallAPKOption(option_parser, options): 52 def ValidateInstallAPKOption(option_parser, options, args):
53 """Validates the apk option and potentially qualifies the path.""" 53 """Validates the apk option and potentially qualifies the path."""
54 if not options.apk: 54 if not options.apk:
55 option_parser.error('--apk is mandatory.') 55 if len(args) > 1:
56 options.apk = args[1]
57 else:
58 option_parser.error('apk target not specified.')
59 return
60
61 if not options.apk.endswith(".apk"):
bulach 2014/05/19 10:22:36 nit: here and below, s/"/'/
mlamouri (slow - plz ping) 2014/05/19 13:43:01 Done.
62 options.apk += ".apk"
63
56 if not os.path.exists(options.apk): 64 if not os.path.exists(options.apk):
57 options.apk = os.path.join(constants.GetOutDirectory(), 'apks', 65 options.apk = os.path.join(constants.GetOutDirectory(), 'apks',
58 options.apk) 66 options.apk)
59 67
60 68
61 def _InstallApk(args): 69 def _InstallApk(args):
62 apk_path, apk_package, keep_data, device = args 70 apk_path, apk_package, keep_data, device = args
63 device_utils.DeviceUtils(device=device).old_interface.ManagedInstall( 71 device_utils.DeviceUtils(device=device).old_interface.ManagedInstall(
64 apk_path, keep_data, apk_package) 72 apk_path, keep_data, apk_package)
65 print '----- Installed on %s -----' % device 73 print '----- Installed on %s -----' % device
66 74
67 75
68 def main(argv): 76 def main(argv):
69 parser = optparse.OptionParser() 77 parser = optparse.OptionParser()
78 parser.set_usage("usage: %prog [options] target")
70 AddInstallAPKOption(parser) 79 AddInstallAPKOption(parser)
71 options, args = parser.parse_args(argv) 80 options, args = parser.parse_args(argv)
81
82 if len(args) > 1 and options.apk:
83 parser.error("Appending the apk as argument can't be used with --apk.")
84 elif len(args) > 2:
85 parser.error("Too many arguments.")
86
72 constants.SetBuildType(options.build_type) 87 constants.SetBuildType(options.build_type)
73 ValidateInstallAPKOption(parser, options) 88 ValidateInstallAPKOption(parser, options, args)
74 if len(args) > 1:
75 raise Exception('Error: Unknown argument:', args[1:])
76 89
77 devices = android_commands.GetAttachedDevices() 90 devices = android_commands.GetAttachedDevices()
78 if not devices: 91 if not devices:
79 raise Exception('Error: no connected devices') 92 raise Exception('Error: no connected devices')
80 93
81 if not options.apk_package: 94 if not options.apk_package:
82 options.apk_package = apk_helper.GetPackageName(options.apk) 95 options.apk_package = apk_helper.GetPackageName(options.apk)
83 96
84 pool = multiprocessing.Pool(len(devices)) 97 pool = multiprocessing.Pool(len(devices))
85 # Send a tuple (apk_path, apk_package, device) per device. 98 # Send a tuple (apk_path, apk_package, device) per device.
86 pool.map(_InstallApk, zip([options.apk] * len(devices), 99 pool.map(_InstallApk, zip([options.apk] * len(devices),
87 [options.apk_package] * len(devices), 100 [options.apk_package] * len(devices),
88 [options.keep_data] * len(devices), 101 [options.keep_data] * len(devices),
89 devices)) 102 devices))
90 103
91 104
92 if __name__ == '__main__': 105 if __name__ == '__main__':
93 sys.exit(main(sys.argv)) 106 sys.exit(main(sys.argv))
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