OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import logging | 5 import logging |
6 import os | 6 import os |
7 import re | 7 import re |
8 import sys | 8 import sys |
9 import time | 9 import time |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 raise Exception('Error while running adb forward.') | 81 raise Exception('Error while running adb forward.') |
82 | 82 |
83 (exit_code, output) = self._adb.GetShellCommandStatusAndOutput( | 83 (exit_code, output) = self._adb.GetShellCommandStatusAndOutput( |
84 '%s %s %s' % (tool.GetUtilWrapper(), Forwarder._DEVICE_FORWARDER_PATH, | 84 '%s %s %s' % (tool.GetUtilWrapper(), Forwarder._DEVICE_FORWARDER_PATH, |
85 Forwarder._DEVICE_ADB_CONTROL_PORT)) | 85 Forwarder._DEVICE_ADB_CONTROL_PORT)) |
86 if exit_code != 0: | 86 if exit_code != 0: |
87 raise Exception( | 87 raise Exception( |
88 'Failed to start device forwarder:\n%s' % '\n'.join(output)) | 88 'Failed to start device forwarder:\n%s' % '\n'.join(output)) |
89 | 89 |
90 for redirection_command in redirection_commands: | 90 for redirection_command in redirection_commands: |
91 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( | 91 try: |
92 [self._host_forwarder_path, redirection_command]) | 92 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( |
| 93 [self._host_forwarder_path, redirection_command]) |
| 94 except OSError as e: |
| 95 if e.errno == 2: |
| 96 raise Exception('Unable to start host forwarder. Make sure you have ' |
| 97 'built host_forwarder.') |
| 98 else: raise |
93 if exit_code != 0: | 99 if exit_code != 0: |
94 raise Exception('%s exited with %d:\n%s' % ( | 100 raise Exception('%s exited with %d:\n%s' % ( |
95 self._host_forwarder_path, exit_code, '\n'.join(output))) | 101 self._host_forwarder_path, exit_code, '\n'.join(output))) |
96 tokens = output.split(':') | 102 tokens = output.split(':') |
97 if len(tokens) != 2: | 103 if len(tokens) != 2: |
98 raise Exception('Unexpected host forwarder output "%s", ' + | 104 raise Exception('Unexpected host forwarder output "%s", ' + |
99 'expected "device_port:host_port"' % output) | 105 'expected "device_port:host_port"' % output) |
100 device_port = int(tokens[0]) | 106 device_port = int(tokens[0]) |
101 host_port = int(tokens[1]) | 107 host_port = int(tokens[1]) |
102 self._host_to_device_port_map[host_port] = device_port | 108 self._host_to_device_port_map[host_port] = device_port |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 143 |
138 def DevicePortForHostPort(self, host_port): | 144 def DevicePortForHostPort(self, host_port): |
139 """Get the device port that corresponds to a given host port.""" | 145 """Get the device port that corresponds to a given host port.""" |
140 return self._host_to_device_port_map.get(host_port) | 146 return self._host_to_device_port_map.get(host_port) |
141 | 147 |
142 def Close(self): | 148 def Close(self): |
143 """Terminate the forwarder process.""" | 149 """Terminate the forwarder process.""" |
144 if self._device_process: | 150 if self._device_process: |
145 self._device_process.close() | 151 self._device_process.close() |
146 self._device_process = None | 152 self._device_process = None |
OLD | NEW |