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| |
(...skipping 14 matching lines...) Expand all Loading... |
25 'host_port [device_port_2 host_port_2] ...', | 25 'host_port [device_port_2 host_port_2] ...', |
26 description=__doc__) | 26 description=__doc__) |
27 parser.add_option('-v', | 27 parser.add_option('-v', |
28 '--verbose', | 28 '--verbose', |
29 dest='verbose_count', | 29 dest='verbose_count', |
30 default=0, | 30 default=0, |
31 action='count', | 31 action='count', |
32 help='Verbose level (multiple times for more)') | 32 help='Verbose level (multiple times for more)') |
33 parser.add_option('--device', | 33 parser.add_option('--device', |
34 help='Serial number of device we should use.') | 34 help='Serial number of device we should use.') |
35 parser.add_option('--host', | |
36 help='Host address to forward to from the host machine. ' | |
37 '127.0.0.1 by default', default='127.0.0.1') | |
38 parser.add_option('--debug', action='store_const', const='Debug', | 35 parser.add_option('--debug', action='store_const', const='Debug', |
39 dest='build_type', default='Release', | 36 dest='build_type', default='Release', |
40 help='Use Debug build of host tools instead of Release.') | 37 help='Use Debug build of host tools instead of Release.') |
41 | 38 |
42 options, args = parser.parse_args(argv) | 39 options, args = parser.parse_args(argv) |
43 run_tests_helper.SetLogLevel(options.verbose_count) | 40 run_tests_helper.SetLogLevel(options.verbose_count) |
44 | 41 |
45 if len(args) < 2 or not len(args) % 2: | 42 if len(args) < 2 or not len(args) % 2: |
46 parser.error('Need even number of port pairs') | 43 parser.error('Need even number of port pairs') |
47 sys.exit(1) | 44 sys.exit(1) |
48 | 45 |
49 try: | 46 try: |
50 port_pairs = map(int, args[1:]) | 47 port_pairs = map(int, args[1:]) |
51 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) | 48 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) |
52 except ValueError: | 49 except ValueError: |
53 parser.error('Bad port number') | 50 parser.error('Bad port number') |
54 sys.exit(1) | 51 sys.exit(1) |
55 | 52 |
56 adb = android_commands.AndroidCommands(options.device) | 53 adb = android_commands.AndroidCommands(options.device) |
57 tool = CreateTool(None, adb) | 54 tool = CreateTool(None, adb) |
58 forwarder_instance = forwarder.Forwarder(adb, options.build_type) | 55 forwarder_instance = forwarder.Forwarder(adb, options.build_type) |
59 try: | 56 try: |
60 forwarder_instance.Run(port_pairs, tool, options.host) | 57 forwarder_instance.Run(port_pairs, tool) |
61 while True: | 58 while True: |
62 time.sleep(60) | 59 time.sleep(60) |
63 except KeyboardInterrupt: | 60 except KeyboardInterrupt: |
64 sys.exit(0) | 61 sys.exit(0) |
65 finally: | 62 finally: |
66 forwarder_instance.Close() | 63 forwarder_instance.Close() |
67 | 64 |
68 | 65 |
69 if __name__ == '__main__': | 66 if __name__ == '__main__': |
70 main(sys.argv) | 67 main(sys.argv) |
OLD | NEW |