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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 devices = android_commands.GetAttachedDevices() | 54 devices = android_commands.GetAttachedDevices() |
55 | 55 |
56 if options.device: | 56 if options.device: |
57 if options.device not in devices: | 57 if options.device not in devices: |
58 raise Exception('Error: %s not in attached devices %s' % (options.device, | 58 raise Exception('Error: %s not in attached devices %s' % (options.device, |
59 ','.join(devices))) | 59 ','.join(devices))) |
60 devices = [options.device] | 60 devices = [options.device] |
61 else: | 61 else: |
62 if not devices: | 62 if not devices: |
63 raise Exception('Error: no connected devices') | 63 raise Exception('Error: no connected devices') |
64 print("No device specified. Defaulting to " + devices[0]) | 64 print "No device specified. Defaulting to " + devices[0] |
65 | 65 |
66 device = device_utils.DeviceUtils(devices[0]) | 66 device = device_utils.DeviceUtils(devices[0]) |
67 constants.SetBuildType(options.build_type) | 67 constants.SetBuildType(options.build_type) |
68 try: | 68 try: |
69 forwarder.Forwarder.Map(port_pairs, device) | 69 forwarder.Forwarder.Map(port_pairs, device) |
70 while True: | 70 while True: |
71 time.sleep(60) | 71 time.sleep(60) |
72 except KeyboardInterrupt: | 72 except KeyboardInterrupt: |
73 sys.exit(0) | 73 sys.exit(0) |
74 finally: | 74 finally: |
75 forwarder.Forwarder.UnmapAllDevicePorts(device) | 75 forwarder.Forwarder.UnmapAllDevicePorts(device) |
76 | 76 |
77 if __name__ == '__main__': | 77 if __name__ == '__main__': |
78 main(sys.argv) | 78 main(sys.argv) |
OLD | NEW |