Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """This module wraps Android's adb tool. | 5 """This module wraps Android's adb tool. |
| 6 | 6 |
| 7 This is a thin wrapper around the adb interface. Any additional complexity | 7 This is a thin wrapper around the adb interface. Any additional complexity |
| 8 should be delegated to a higher level (ex. DeviceUtils). | 8 should be delegated to a higher level (ex. DeviceUtils). |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 Returns: | 164 Returns: |
| 165 The output of the shell command as a string. | 165 The output of the shell command as a string. |
| 166 | 166 |
| 167 Raises: | 167 Raises: |
| 168 device_errors.AdbCommandFailedError: If the return code doesn't match | 168 device_errors.AdbCommandFailedError: If the return code doesn't match |
| 169 |expect_rc|. | 169 |expect_rc|. |
| 170 """ | 170 """ |
| 171 if expect_rc is None: | 171 if expect_rc is None: |
| 172 actual_command = command | 172 actual_command = command |
| 173 else: | 173 else: |
| 174 actual_command = '%s; echo $?;' % command | 174 actual_command = '%s; echo %%$?;' % command.rstrip() |
| 175 output = self._DeviceAdbCmd( | 175 output = self._DeviceAdbCmd( |
| 176 ['shell', actual_command], timeout, retries, check_error=False) | 176 ['shell', actual_command], timeout, retries, check_error=False) |
| 177 if expect_rc is not None: | 177 if expect_rc is not None: |
| 178 output_end = output.rstrip().rfind('\n') + 1 | 178 output_end = output.rfind('%') |
|
perezju
2014/10/20 16:20:01
Trying to find our own marker, rather than a new l
| |
| 179 rc = output[output_end:].strip() | 179 if output_end < 0: |
| 180 # causes the string for rc to become empty and also raise a ValueError | |
| 181 output_end = len(output) | |
| 182 | |
| 183 try: | |
| 184 rc = int(output[output_end+1:]) | |
| 185 except ValueError: | |
| 186 raise device_errors.AdbCommandFailedError( | |
| 187 ['shell'], 'command %r on device produced output %r where no' | |
| 188 ' valid return code was found' % (actual_command, output), | |
| 189 self._device_serial) | |
| 190 | |
| 180 output = output[:output_end] | 191 output = output[:output_end] |
| 181 if int(rc) != expect_rc: | 192 if rc != expect_rc: |
| 182 raise device_errors.AdbCommandFailedError( | 193 raise device_errors.AdbShellCommandFailedError( |
| 183 ['shell', command], | 194 command, rc, output, self._device_serial) |
| 184 'shell command exited with code: %s' % rc, | |
| 185 self._device_serial) | |
| 186 return output | 195 return output |
| 187 | 196 |
| 188 def Logcat(self, filter_spec=None, timeout=_DEFAULT_TIMEOUT, | 197 def Logcat(self, filter_spec=None, timeout=_DEFAULT_TIMEOUT, |
| 189 retries=_DEFAULT_RETRIES): | 198 retries=_DEFAULT_RETRIES): |
| 190 """Get the logcat output. | 199 """Get the logcat output. |
| 191 | 200 |
| 192 Args: | 201 Args: |
| 193 filter_spec: (optional) Spec to filter the logcat. | 202 filter_spec: (optional) Spec to filter the logcat. |
| 194 timeout: (optional) Timeout per try in seconds. | 203 timeout: (optional) Timeout per try in seconds. |
| 195 retries: (optional) Number of retries to attempt. | 204 retries: (optional) Number of retries to attempt. |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 """Restarts the adbd daemon with root permissions, if possible. | 387 """Restarts the adbd daemon with root permissions, if possible. |
| 379 | 388 |
| 380 Args: | 389 Args: |
| 381 timeout: (optional) Timeout per try in seconds. | 390 timeout: (optional) Timeout per try in seconds. |
| 382 retries: (optional) Number of retries to attempt. | 391 retries: (optional) Number of retries to attempt. |
| 383 """ | 392 """ |
| 384 output = self._DeviceAdbCmd(['root'], timeout, retries) | 393 output = self._DeviceAdbCmd(['root'], timeout, retries) |
| 385 if 'cannot' in output: | 394 if 'cannot' in output: |
| 386 raise device_errors.AdbCommandFailedError(['root'], output) | 395 raise device_errors.AdbCommandFailedError(['root'], output) |
| 387 | 396 |
| OLD | NEW |