| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 parser.error('Need even number of port pairs') | 48 parser.error('Need even number of port pairs') |
| 49 sys.exit(1) | 49 sys.exit(1) |
| 50 | 50 |
| 51 try: | 51 try: |
| 52 port_pairs = [int(a) for a in args[1:]] | 52 port_pairs = [int(a) for a in args[1:]] |
| 53 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) | 53 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) |
| 54 except ValueError: | 54 except ValueError: |
| 55 parser.error('Bad port number') | 55 parser.error('Bad port number') |
| 56 sys.exit(1) | 56 sys.exit(1) |
| 57 | 57 |
| 58 blacklist = (device_blacklist.Blacklist(options.blacklist_file) | 58 if options.blacklist_file: |
| 59 if options.blacklist_file | 59 blacklist = device_blacklist.Blacklist(options.blacklist_file) |
| 60 else None) | 60 else: |
| 61 blacklist = None |
| 62 |
| 61 devices = device_utils.DeviceUtils.HealthyDevices(blacklist) | 63 devices = device_utils.DeviceUtils.HealthyDevices(blacklist) |
| 62 | 64 |
| 63 if options.device: | 65 if options.device: |
| 64 device = next((d for d in devices if d == options.device), None) | 66 device = next((d for d in devices if d == options.device), None) |
| 65 if not device: | 67 if not device: |
| 66 raise device_errors.DeviceUnreachableError(options.device) | 68 raise device_errors.DeviceUnreachableError(options.device) |
| 67 elif devices: | 69 elif devices: |
| 68 device = devices[0] | 70 device = devices[0] |
| 69 logging.info('No device specified. Defaulting to %s', devices[0]) | 71 logging.info('No device specified. Defaulting to %s', devices[0]) |
| 70 else: | 72 else: |
| 71 raise device_errors.NoDevicesError() | 73 raise device_errors.NoDevicesError() |
| 72 | 74 |
| 73 constants.SetBuildType(options.build_type) | 75 constants.SetBuildType(options.build_type) |
| 74 try: | 76 try: |
| 75 forwarder.Forwarder.Map(port_pairs, device) | 77 forwarder.Forwarder.Map(port_pairs, device) |
| 76 while True: | 78 while True: |
| 77 time.sleep(60) | 79 time.sleep(60) |
| 78 except KeyboardInterrupt: | 80 except KeyboardInterrupt: |
| 79 sys.exit(0) | 81 sys.exit(0) |
| 80 finally: | 82 finally: |
| 81 forwarder.Forwarder.UnmapAllDevicePorts(device) | 83 forwarder.Forwarder.UnmapAllDevicePorts(device) |
| 82 | 84 |
| 83 if __name__ == '__main__': | 85 if __name__ == '__main__': |
| 84 main(sys.argv) | 86 main(sys.argv) |
| OLD | NEW |