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

Unified Diff: build/android/adb_install_apk.py

Issue 1181093002: [Android] Make adb_install_apk use the device blacklist. (RELAND) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/adb_install_apk.py
diff --git a/build/android/adb_install_apk.py b/build/android/adb_install_apk.py
index 00bd38e1821d7957efcc5ffbd0dc9bc027f6fd09..1e370f8fa8ea4c765a5bb003b94a666473c9d08b 100755
--- a/build/android/adb_install_apk.py
+++ b/build/android/adb_install_apk.py
@@ -6,84 +6,86 @@
"""Utility script to install APKs from the command line quickly."""
-import optparse
+import argparse
+import logging
import os
import sys
from pylib import constants
+from pylib.device import device_blacklist
from pylib.device import device_errors
from pylib.device import device_utils
-
-
-def AddInstallAPKOption(option_parser):
- """Adds apk option used to install the APK to the OptionParser."""
- option_parser.add_option('--apk',
- help=('DEPRECATED The name of the apk containing the'
- ' application (with the .apk extension).'))
- option_parser.add_option('--apk_package',
- help=('DEPRECATED The package name used by the apk '
- 'containing the application.'))
- option_parser.add_option('--keep_data',
- action='store_true',
- default=False,
- help=('Keep the package data when installing '
- 'the application.'))
- option_parser.add_option('--debug', action='store_const', const='Debug',
- dest='build_type',
- default=os.environ.get('BUILDTYPE', 'Debug'),
- help='If set, run test suites under out/Debug. '
+from pylib.utils import run_tests_helper
+
+
+def main():
+ parser = argparse.ArgumentParser()
+
+ apk_group = parser.add_mutually_exclusive_group(required=True)
+ apk_group.add_argument('--apk', dest='apk_name',
+ help='DEPRECATED The name of the apk containing the'
+ ' application (with the .apk extension).')
+ apk_group.add_argument('apk_path', nargs='?',
+ help='The path to the APK to install.')
+
+ # TODO(jbudorick): Remove once no clients pass --apk_package
+ parser.add_argument('--apk_package', help='DEPRECATED unused')
+ parser.add_argument('--keep_data',
+ action='store_true',
+ default=False,
+ help='Keep the package data when installing '
+ 'the application.')
+ parser.add_argument('--debug', action='store_const', const='Debug',
+ dest='build_type',
+ default=os.environ.get('BUILDTYPE', 'Debug'),
+ help='If set, run test suites under out/Debug. '
'Default is env var BUILDTYPE or Debug')
- option_parser.add_option('--release', action='store_const', const='Release',
- dest='build_type',
- help='If set, run test suites under out/Release. '
+ parser.add_argument('--release', action='store_const', const='Release',
+ dest='build_type',
+ help='If set, run test suites under out/Release. '
'Default is env var BUILDTYPE or Debug.')
- option_parser.add_option('-d', '--device', dest='device',
- help='Target device for apk to install on.')
-
-
-def ValidateInstallAPKOption(option_parser, options, args):
- """Validates the apk option and potentially qualifies the path."""
- if not options.apk:
- if len(args) > 1:
- options.apk = args[1]
- else:
- option_parser.error('apk target not specified.')
+ parser.add_argument('-d', '--device', dest='device',
+ help='Target device for apk to install on.')
+ parser.add_argument('-v', '--verbose', action='count',
+ help='Enable verbose logging.')
- if not options.apk.endswith('.apk'):
- options.apk += '.apk'
+ args = parser.parse_args()
- if not os.path.exists(options.apk):
- options.apk = os.path.join(constants.GetOutDirectory(), 'apks',
- options.apk)
+ run_tests_helper.SetLogLevel(args.verbose)
+ constants.SetBuildType(args.build_type)
-
-def main(argv):
- parser = optparse.OptionParser()
- parser.set_usage("usage: %prog [options] target")
- AddInstallAPKOption(parser)
- options, args = parser.parse_args(argv)
-
- if len(args) > 1 and options.apk:
- parser.error("Appending the apk as argument can't be used with --apk.")
- elif len(args) > 2:
- parser.error("Too many arguments.")
-
- constants.SetBuildType(options.build_type)
- ValidateInstallAPKOption(parser, options, args)
+ apk = args.apk_path or args.apk_name
+ if not apk.endswith('.apk'):
+ apk += '.apk'
+ if not os.path.exists(apk):
+ apk = os.path.join(constants.GetOutDirectory(), 'apks', apk)
+ if not os.path.exists(apk):
+ parser.error('%s not found.' % apk)
devices = device_utils.DeviceUtils.HealthyDevices()
- if options.device:
- devices = [d for d in devices if d == options.device]
+ if args.device:
+ devices = [d for d in devices if d == args.device]
if not devices:
- raise device_errors.DeviceUnreachableError(options.device)
+ raise device_errors.DeviceUnreachableError(args.device)
elif not devices:
raise device_errors.NoDevicesError()
- device_utils.DeviceUtils.parallel(devices).Install(
- options.apk, reinstall=options.keep_data)
+ def blacklisting_install(device):
+ try:
+ device.Install(apk, reinstall=args.keep_data)
+ except device_errors.CommandFailedError:
+ logging.exception('Failed to install %s', args.apk)
+ device_blacklist.ExtendBlacklist([str(device)])
+ logging.warning('Blacklisting %s', str(device))
+ except device_errors.CommandTimeoutError:
+ logging.exception('Timed out while installing %s', args.apk)
+ device_blacklist.ExtendBlacklist([str(device)])
+ logging.warning('Blacklisting %s', str(device))
+
+ device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install)
if __name__ == '__main__':
- sys.exit(main(sys.argv))
+ sys.exit(main())
« 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