| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2013 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 """Command line tool for forwarding ports from a device to the host. | 7 """Command line tool for forwarding ports from a device to the host. |
| 8 | 8 |
| 9 Allows an Android device to connect to services running on the host machine, | 9 Allows an Android device to connect to services running on the host machine, |
| 10 i.e., "adb forward" in reverse. Requires |host_forwarder| and |device_forwarder| | 10 i.e., "adb forward" in reverse. Requires |host_forwarder| and |device_forwarder| |
| 11 to be built. | 11 to be built. |
| 12 """ | 12 """ |
| 13 | 13 |
| 14 import logging | 14 import logging |
| 15 import optparse | 15 import optparse |
| 16 import sys | 16 import sys |
| 17 import time | 17 import time |
| 18 | 18 |
| 19 from devil.android import device_blacklist | 19 from devil.android import device_blacklist |
| 20 from devil.android import device_errors | 20 from devil.android import device_errors |
| 21 from devil.android import device_utils | 21 from devil.android import device_utils |
| 22 from devil.android.sdk import adb_wrapper | |
| 23 from devil.utils import run_tests_helper | 22 from devil.utils import run_tests_helper |
| 24 from pylib import constants | 23 from pylib import constants |
| 25 from pylib import forwarder | 24 from pylib import forwarder |
| 26 | 25 |
| 27 | 26 |
| 28 def main(argv): | 27 def main(argv): |
| 29 parser = optparse.OptionParser(usage='Usage: %prog [options] device_port ' | 28 parser = optparse.OptionParser(usage='Usage: %prog [options] device_port ' |
| 30 'host_port [device_port_2 host_port_2] ...', | 29 'host_port [device_port_2 host_port_2] ...', |
| 31 description=__doc__) | 30 description=__doc__) |
| 32 parser.add_option('-v', | 31 parser.add_option('-v', |
| (...skipping 10 matching lines...) Expand all Loading... |
| 43 help='Use Debug build of host tools instead of Release.') | 42 help='Use Debug build of host tools instead of Release.') |
| 44 | 43 |
| 45 options, args = parser.parse_args(argv) | 44 options, args = parser.parse_args(argv) |
| 46 run_tests_helper.SetLogLevel(options.verbose_count) | 45 run_tests_helper.SetLogLevel(options.verbose_count) |
| 47 | 46 |
| 48 if len(args) < 2 or not len(args) % 2: | 47 if len(args) < 2 or not len(args) % 2: |
| 49 parser.error('Need even number of port pairs') | 48 parser.error('Need even number of port pairs') |
| 50 sys.exit(1) | 49 sys.exit(1) |
| 51 | 50 |
| 52 try: | 51 try: |
| 53 port_pairs = map(int, args[1:]) | 52 port_pairs = [int(a) for a in args[1:]] |
| 54 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) | 53 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) |
| 55 except ValueError: | 54 except ValueError: |
| 56 parser.error('Bad port number') | 55 parser.error('Bad port number') |
| 57 sys.exit(1) | 56 sys.exit(1) |
| 58 | 57 |
| 59 if options.blacklist_file: | 58 if options.blacklist_file: |
| 60 blacklist = device_blacklist.Blacklist(options.blacklist_file) | 59 blacklist = device_blacklist.Blacklist(options.blacklist_file) |
| 61 else: | 60 else: |
| 62 blacklist = None | 61 blacklist = None |
| 63 | 62 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 78 forwarder.Forwarder.Map(port_pairs, device) | 77 forwarder.Forwarder.Map(port_pairs, device) |
| 79 while True: | 78 while True: |
| 80 time.sleep(60) | 79 time.sleep(60) |
| 81 except KeyboardInterrupt: | 80 except KeyboardInterrupt: |
| 82 sys.exit(0) | 81 sys.exit(0) |
| 83 finally: | 82 finally: |
| 84 forwarder.Forwarder.UnmapAllDevicePorts(device) | 83 forwarder.Forwarder.UnmapAllDevicePorts(device) |
| 85 | 84 |
| 86 if __name__ == '__main__': | 85 if __name__ == '__main__': |
| 87 main(sys.argv) | 86 main(sys.argv) |
| OLD | NEW |