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 import devil_chromium |
| 20 |
19 from devil.android import device_blacklist | 21 from devil.android import device_blacklist |
20 from devil.android import device_errors | 22 from devil.android import device_errors |
21 from devil.android import device_utils | 23 from devil.android import device_utils |
22 from devil.android import forwarder | 24 from devil.android import forwarder |
23 from devil.utils import run_tests_helper | 25 from devil.utils import run_tests_helper |
| 26 |
24 from pylib import constants | 27 from pylib import constants |
25 | 28 |
26 | 29 |
27 def main(argv): | 30 def main(argv): |
28 parser = optparse.OptionParser(usage='Usage: %prog [options] device_port ' | 31 parser = optparse.OptionParser(usage='Usage: %prog [options] device_port ' |
29 'host_port [device_port_2 host_port_2] ...', | 32 'host_port [device_port_2 host_port_2] ...', |
30 description=__doc__) | 33 description=__doc__) |
31 parser.add_option('-v', | 34 parser.add_option('-v', |
32 '--verbose', | 35 '--verbose', |
33 dest='verbose_count', | 36 dest='verbose_count', |
34 default=0, | 37 default=0, |
35 action='count', | 38 action='count', |
36 help='Verbose level (multiple times for more)') | 39 help='Verbose level (multiple times for more)') |
37 parser.add_option('--device', | 40 parser.add_option('--device', |
38 help='Serial number of device we should use.') | 41 help='Serial number of device we should use.') |
39 parser.add_option('--blacklist-file', help='Device blacklist JSON file.') | 42 parser.add_option('--blacklist-file', help='Device blacklist JSON file.') |
40 parser.add_option('--debug', action='store_const', const='Debug', | 43 parser.add_option('--debug', action='store_const', const='Debug', |
41 dest='build_type', default='Release', | 44 dest='build_type', default='Release', |
42 help='Use Debug build of host tools instead of Release.') | 45 help='Use Debug build of host tools instead of Release.') |
43 | 46 |
44 options, args = parser.parse_args(argv) | 47 options, args = parser.parse_args(argv) |
45 run_tests_helper.SetLogLevel(options.verbose_count) | 48 run_tests_helper.SetLogLevel(options.verbose_count) |
46 | 49 |
| 50 devil_chromium.Initialize() |
| 51 |
47 if len(args) < 2 or not len(args) % 2: | 52 if len(args) < 2 or not len(args) % 2: |
48 parser.error('Need even number of port pairs') | 53 parser.error('Need even number of port pairs') |
49 sys.exit(1) | 54 sys.exit(1) |
50 | 55 |
51 try: | 56 try: |
52 port_pairs = [int(a) for a in args[1:]] | 57 port_pairs = [int(a) for a in args[1:]] |
53 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) | 58 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) |
54 except ValueError: | 59 except ValueError: |
55 parser.error('Bad port number') | 60 parser.error('Bad port number') |
56 sys.exit(1) | 61 sys.exit(1) |
(...skipping 18 matching lines...) Expand all Loading... |
75 forwarder.Forwarder.Map(port_pairs, device) | 80 forwarder.Forwarder.Map(port_pairs, device) |
76 while True: | 81 while True: |
77 time.sleep(60) | 82 time.sleep(60) |
78 except KeyboardInterrupt: | 83 except KeyboardInterrupt: |
79 sys.exit(0) | 84 sys.exit(0) |
80 finally: | 85 finally: |
81 forwarder.Forwarder.UnmapAllDevicePorts(device) | 86 forwarder.Forwarder.UnmapAllDevicePorts(device) |
82 | 87 |
83 if __name__ == '__main__': | 88 if __name__ == '__main__': |
84 main(sys.argv) | 89 main(sys.argv) |
OLD | NEW |