|
54 | 54 | from devlib.exception import (DevlibTransientError, TargetStableError,
|
55 | 55 | TargetNotRespondingError, TimeoutError,
|
56 | 56 | TargetTransientError, KernelConfigKeyError,
|
57 |
| - TargetError, HostError, TargetCalledProcessError) # pylint: disable=redefined-builtin |
| 57 | + TargetError, HostError, TargetCalledProcessError, |
| 58 | + TargetStableCalledProcessError, TargetTransientCalledProcessError, |
| 59 | + ) # pylint: disable=redefined-builtin |
58 | 60 | from devlib.utils.ssh import SshConnection
|
59 | 61 | from devlib.utils.android import AdbConnection, AndroidProperties, LogcatMonitor, adb_command, adb_disconnect, INTENT_FLAGS
|
60 | 62 | from devlib.utils.misc import memoized, isiterable, convert_new_lines, groupby_value
|
@@ -888,6 +890,32 @@ def _execute(self, command, timeout=None, check_exit_code=True,
|
888 | 890 | check_exit_code=check_exit_code, as_root=as_root,
|
889 | 891 | strip_colors=strip_colors, will_succeed=will_succeed)
|
890 | 892 |
|
| 893 | + @asyn.asyncf |
| 894 | + @call_conn |
| 895 | + async def execute_raw(self, command, *, timeout=None, check_exit_code=True, |
| 896 | + as_root=False, will_succeed=False, force_locale='C'): |
| 897 | + bg = self.background( |
| 898 | + command=command, |
| 899 | + as_root=as_root, |
| 900 | + force_locale=force_locale, |
| 901 | + ) |
| 902 | + |
| 903 | + # TODO: make BackgroundCommand API async-friendly and use that |
| 904 | + with bg as bg: |
| 905 | + try: |
| 906 | + # Timeout on communicate() usually saves a thread |
| 907 | + stdout, stderr = bg.communicate(timeout=timeout) |
| 908 | + except subprocess.CalledProcessError as e: |
| 909 | + if check_exit_code: |
| 910 | + if will_succeed: |
| 911 | + raise TargetTransientCalledProcessError(*e.args) |
| 912 | + else: |
| 913 | + raise |
| 914 | + else: |
| 915 | + return (e.stdout, e.stderr) |
| 916 | + else: |
| 917 | + return (stdout, stderr) |
| 918 | + |
891 | 919 | execute = asyn._AsyncPolymorphicFunction(
|
892 | 920 | asyn=_execute_async.asyn,
|
893 | 921 | blocking=_execute,
|
|
0 commit comments