OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """Provides a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
6 | 6 |
7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
8 """ | 8 """ |
9 # pylint: disable=W0613 | 9 # pylint: disable=W0613 |
10 | 10 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 for line in out.splitlines(): | 364 for line in out.splitlines(): |
365 if 'Failure' in line: | 365 if 'Failure' in line: |
366 raise device_errors.CommandFailedError( | 366 raise device_errors.CommandFailedError( |
367 line.strip(), device=str(self)) | 367 line.strip(), device=str(self)) |
368 except AssertionError as e: | 368 except AssertionError as e: |
369 raise device_errors.CommandFailedError( | 369 raise device_errors.CommandFailedError( |
370 str(e), device=str(self)), None, sys.exc_info()[2] | 370 str(e), device=str(self)), None, sys.exc_info()[2] |
371 | 371 |
372 @decorators.WithTimeoutAndRetriesFromInstance() | 372 @decorators.WithTimeoutAndRetriesFromInstance() |
373 def RunShellCommand(self, cmd, check_return=False, cwd=None, env=None, | 373 def RunShellCommand(self, cmd, check_return=False, cwd=None, env=None, |
374 as_root=False, single_line=False, | 374 as_root=False, single_line=False, raw_output=False, |
jbudorick
2014/11/18 02:29:37
I'm wary of adding options simply for convenience
| |
375 timeout=None, retries=None): | 375 timeout=None, retries=None): |
376 """Run an ADB shell command. | 376 """Run an ADB shell command. |
377 | 377 |
378 The command to run |cmd| should be a sequence of program arguments or else | 378 The command to run |cmd| should be a sequence of program arguments or else |
379 a single string. | 379 a single string. |
380 | 380 |
381 When |cmd| is a sequence, it is assumed to contain the name of the command | 381 When |cmd| is a sequence, it is assumed to contain the name of the command |
382 to run followed by its arguments. In this case, arguments are passed to the | 382 to run followed by its arguments. In this case, arguments are passed to the |
383 command exactly as given, without any further processing by the shell. This | 383 command exactly as given, without any further processing by the shell. This |
384 allows to easily pass arguments containing spaces or special characters | 384 allows to easily pass arguments containing spaces or special characters |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 timeout = self._default_timeout | 440 timeout = self._default_timeout |
441 | 441 |
442 try: | 442 try: |
443 output = self.adb.Shell(cmd) | 443 output = self.adb.Shell(cmd) |
444 except device_errors.AdbShellCommandFailedError as e: | 444 except device_errors.AdbShellCommandFailedError as e: |
445 if check_return: | 445 if check_return: |
446 raise | 446 raise |
447 else: | 447 else: |
448 output = e.output | 448 output = e.output |
449 | 449 |
450 if raw_output: | |
451 return output | |
452 | |
450 output = output.splitlines() | 453 output = output.splitlines() |
451 if single_line: | 454 if single_line: |
452 if not output: | 455 if not output: |
453 return '' | 456 return '' |
454 elif len(output) == 1: | 457 elif len(output) == 1: |
455 return output[0] | 458 return output[0] |
456 else: | 459 else: |
457 msg = 'one line of output was expected, but got: %s' | 460 msg = 'one line of output was expected, but got: %s' |
458 raise device_errors.CommandFailedError(msg % output, str(self)) | 461 raise device_errors.CommandFailedError(msg % output, str(self)) |
459 else: | 462 else: |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1166 Returns: | 1169 Returns: |
1167 A Parallelizer operating over |devices|. | 1170 A Parallelizer operating over |devices|. |
1168 """ | 1171 """ |
1169 if not devices or len(devices) == 0: | 1172 if not devices or len(devices) == 0: |
1170 devices = pylib.android_commands.GetAttachedDevices() | 1173 devices = pylib.android_commands.GetAttachedDevices() |
1171 parallelizer_type = (parallelizer.Parallelizer if async | 1174 parallelizer_type = (parallelizer.Parallelizer if async |
1172 else parallelizer.SyncParallelizer) | 1175 else parallelizer.SyncParallelizer) |
1173 return parallelizer_type([ | 1176 return parallelizer_type([ |
1174 d if isinstance(d, DeviceUtils) else DeviceUtils(d) | 1177 d if isinstance(d, DeviceUtils) else DeviceUtils(d) |
1175 for d in devices]) | 1178 for d in devices]) |
OLD | NEW |