OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
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 | |
5 # found in the LICENSE file. | |
6 | |
7 """Command line tool for forwarding ports from a device to the host. | |
8 | |
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| | |
11 to be built. | |
12 """ | |
13 | |
14 import optparse | |
15 import sys | |
16 import time | |
17 | |
18 from pylib import android_commands, forwarder | |
19 from pylib.utils import run_tests_helper | |
20 | |
21 | |
22 def main(argv): | |
23 parser = optparse.OptionParser(usage='Usage: %prog [options] device_port ' | |
24 'host_port [device_port_2 host_port_2] ...', | |
25 description=__doc__) | |
26 parser.add_option('-v', | |
27 '--verbose', | |
28 dest='verbose_count', | |
29 default=0, | |
30 action='count', | |
31 help='Verbose level (multiple times for more)') | |
32 parser.add_option('--device', | |
33 help='Serial number of device we should use.') | |
34 parser.add_option('--host', | |
35 help='Host address to forward to from the host machine. ' | |
36 '127.0.0.1 by default', default='127.0.0.1') | |
37 parser.add_option('--debug', action='store_const', const='Debug', | |
38 dest='build_type', default='Release', | |
39 help='Use Debug build of host tools instead of Release.') | |
40 | |
41 options, args = parser.parse_args(argv) | |
42 run_tests_helper.SetLogLevel(options.verbose_count) | |
43 | |
44 if len(args) < 2 or not len(args) % 2: | |
45 parser.error('Need even number of port pairs') | |
46 sys.exit(1) | |
47 | |
48 try: | |
49 port_pairs = map(int, args[1:]) | |
50 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) | |
51 except ValueError: | |
52 parser.error('Bad port number') | |
53 sys.exit(1) | |
54 | |
55 adb = android_commands.AndroidCommands(options.device) | |
56 forwarder_instance = forwarder.Forwarder(adb, options.build_type) | |
57 try: | |
58 forwarder_instance.Run(port_pairs, None, options.host) | |
59 while True: | |
60 time.sleep(60) | |
61 except KeyboardInterrupt: | |
62 sys.exit(0) | |
63 finally: | |
64 forwarder_instance.Close() | |
Philippe
2013/01/11 13:50:03
Forwarder::Close() should have been removed. It's
| |
65 | |
66 | |
67 if __name__ == '__main__': | |
68 main(sys.argv) | |
OLD | NEW |