[Android] Switch adb_reverse_forwarder to argparse.
Also, add newlines to host forwarder error logging. BUG= Review-Url: https://codereview.chromium.org/2364733003 Cr-Original-Commit-Position: refs/heads/master@{#420552} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: d9bce3909e31c1d7ef17c56e61181e0b53788cda
This commit is contained in:
Родитель
52cef92e76
Коммит
87bb8bc8ac
|
@ -11,7 +11,7 @@ i.e., "adb forward" in reverse. Requires |host_forwarder| and |device_forwarder|
|
||||||
to be built.
|
to be built.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import optparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -26,44 +26,57 @@ from pylib import constants
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
parser = optparse.OptionParser(usage='Usage: %prog [options] device_port '
|
parser = argparse.ArgumentParser(
|
||||||
'host_port [device_port_2 host_port_2] ...',
|
usage='Usage: %(prog)s [options] device_port '
|
||||||
description=__doc__)
|
'host_port [device_port_2 host_port_2] ...',
|
||||||
parser.add_option('-v',
|
description=__doc__)
|
||||||
'--verbose',
|
parser.add_argument(
|
||||||
dest='verbose_count',
|
'-v', '--verbose',
|
||||||
default=0,
|
dest='verbose_count',
|
||||||
action='count',
|
default=0,
|
||||||
help='Verbose level (multiple times for more)')
|
action='count',
|
||||||
parser.add_option('--device',
|
help='Verbose level (multiple times for more)')
|
||||||
help='Serial number of device we should use.')
|
parser.add_argument(
|
||||||
parser.add_option('--blacklist-file', help='Device blacklist JSON file.')
|
'--device',
|
||||||
parser.add_option('--debug', action='store_const', const='Debug',
|
help='Serial number of device we should use.')
|
||||||
dest='build_type', default='Release',
|
parser.add_argument(
|
||||||
help='Use Debug build of host tools instead of Release.')
|
'--blacklist-file',
|
||||||
|
help='Device blacklist JSON file.')
|
||||||
|
parser.add_argument(
|
||||||
|
'--debug',
|
||||||
|
action='store_const',
|
||||||
|
const='Debug',
|
||||||
|
dest='build_type',
|
||||||
|
default='Release',
|
||||||
|
help='DEPRECATED: use --output-directory instead.')
|
||||||
|
parser.add_argument(
|
||||||
|
'--output-directory',
|
||||||
|
help='Path to the root build directory.')
|
||||||
|
parser.add_argument(
|
||||||
|
'ports',
|
||||||
|
nargs='+',
|
||||||
|
type=int,
|
||||||
|
help='Port pair to reverse forward.')
|
||||||
|
|
||||||
options, args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
run_tests_helper.SetLogLevel(options.verbose_count)
|
run_tests_helper.SetLogLevel(args.verbose_count)
|
||||||
|
|
||||||
devil_chromium.Initialize()
|
if len(args.ports) < 2 or len(args.ports) % 2:
|
||||||
|
|
||||||
if len(args) < 2 or not len(args) % 2:
|
|
||||||
parser.error('Need even number of port pairs')
|
parser.error('Need even number of port pairs')
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
port_pairs = zip(args.ports[::2], args.ports[1::2])
|
||||||
port_pairs = [int(a) for a in args[1:]]
|
|
||||||
port_pairs = zip(port_pairs[::2], port_pairs[1::2])
|
|
||||||
except ValueError:
|
|
||||||
parser.error('Bad port number')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
blacklist = (device_blacklist.Blacklist(options.blacklist_file)
|
if args.build_type:
|
||||||
if options.blacklist_file
|
constants.SetBuildType(args.build_type)
|
||||||
|
if args.output_directory:
|
||||||
|
constants.SetOutputDirectory(args.output_directory)
|
||||||
|
devil_chromium.Initialize(output_directory=constants.GetOutDirectory())
|
||||||
|
|
||||||
|
blacklist = (device_blacklist.Blacklist(args.blacklist_file)
|
||||||
|
if args.blacklist_file
|
||||||
else None)
|
else None)
|
||||||
device = device_utils.DeviceUtils.HealthyDevices(
|
device = device_utils.DeviceUtils.HealthyDevices(
|
||||||
blacklist=blacklist, device_arg=options.device)[0]
|
blacklist=blacklist, device_arg=args.device)[0]
|
||||||
constants.SetBuildType(options.build_type)
|
|
||||||
try:
|
try:
|
||||||
forwarder.Forwarder.Map(port_pairs, device)
|
forwarder.Forwarder.Map(port_pairs, device)
|
||||||
while True:
|
while True:
|
||||||
|
@ -74,4 +87,4 @@ def main(argv):
|
||||||
forwarder.Forwarder.UnmapAllDevicePorts(device)
|
forwarder.Forwarder.UnmapAllDevicePorts(device)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main(sys.argv)
|
sys.exit(main(sys.argv[1:]))
|
||||||
|
|
Загрузка…
Ссылка в новой задаче