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