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 optparse | 14 import optparse |
15 import sys | 15 import sys |
16 import time | 16 import time |
17 | 17 |
18 from pylib import android_commands, constants, forwarder | 18 from pylib import constants, forwarder |
| 19 from pylib.device import device_utils |
19 from pylib.utils import run_tests_helper | 20 from pylib.utils import run_tests_helper |
20 | 21 |
21 | 22 |
22 def main(argv): | 23 def main(argv): |
23 parser = optparse.OptionParser(usage='Usage: %prog [options] device_port ' | 24 parser = optparse.OptionParser(usage='Usage: %prog [options] device_port ' |
24 'host_port [device_port_2 host_port_2] ...', | 25 'host_port [device_port_2 host_port_2] ...', |
25 description=__doc__) | 26 description=__doc__) |
26 parser.add_option('-v', | 27 parser.add_option('-v', |
27 '--verbose', | 28 '--verbose', |
28 dest='verbose_count', | 29 dest='verbose_count', |
(...skipping 13 matching lines...) Expand all Loading... |
42 parser.error('Need even number of port pairs') | 43 parser.error('Need even number of port pairs') |
43 sys.exit(1) | 44 sys.exit(1) |
44 | 45 |
45 try: | 46 try: |
46 port_pairs = map(int, args[1:]) | 47 port_pairs = map(int, args[1:]) |
47 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) | 48 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) |
48 except ValueError: | 49 except ValueError: |
49 parser.error('Bad port number') | 50 parser.error('Bad port number') |
50 sys.exit(1) | 51 sys.exit(1) |
51 | 52 |
52 adb = android_commands.AndroidCommands(options.device) | 53 device = device_utils.DeviceUtils(options.device) |
53 constants.SetBuildType(options.build_type) | 54 constants.SetBuildType(options.build_type) |
54 try: | 55 try: |
55 forwarder.Forwarder.Map(port_pairs, adb) | 56 forwarder.Forwarder.Map(port_pairs, device) |
56 while True: | 57 while True: |
57 time.sleep(60) | 58 time.sleep(60) |
58 except KeyboardInterrupt: | 59 except KeyboardInterrupt: |
59 sys.exit(0) | 60 sys.exit(0) |
60 finally: | 61 finally: |
61 forwarder.Forwarder.UnmapAllDevicePorts(adb) | 62 forwarder.Forwarder.UnmapAllDevicePorts(device) |
62 | 63 |
63 if __name__ == '__main__': | 64 if __name__ == '__main__': |
64 main(sys.argv) | 65 main(sys.argv) |
OLD | NEW |