|
45 | 45 | from exec_helpers import exec_result
|
46 | 46 | from exec_helpers import proc_enums
|
47 | 47 | from exec_helpers import ssh_auth
|
| 48 | +from exec_helpers.api import CalledProcessErrorSubClassT |
| 49 | +from exec_helpers.api import OptionalStdinT |
| 50 | +from exec_helpers.api import OptionalTimeoutT |
| 51 | +from exec_helpers.proc_enums import ExitCodeT |
48 | 52 |
|
49 | 53 | # Local Implementation
|
50 | 54 | from ._ssh_helpers import HostsSSHConfigs
|
51 | 55 | from ._ssh_helpers import SSHConfig
|
52 | 56 |
|
53 |
| - |
54 | 57 | _OptionalSSHAuthMapT = typing.Optional[typing.Union[typing.Dict[str, ssh_auth.SSHAuth], ssh_auth.SSHAuthMapping]]
|
55 | 58 | _OptionalSSHConfigArgT = typing.Union[
|
56 | 59 | str,
|
|
61 | 64 | ]
|
62 | 65 | _SSHConnChainT = typing.List[typing.Tuple[SSHConfig, ssh_auth.SSHAuth]]
|
63 | 66 | _OptSSHAuthT = typing.Optional[ssh_auth.SSHAuth]
|
64 |
| -_OptTimeoutT = typing.Union[int, float, None] |
65 |
| -_OptStdinT = typing.Union[bytes, str, bytearray, None] |
66 |
| -_ExitCodeT = typing.Union[int, proc_enums.ExitCodes] |
67 | 67 |
|
68 | 68 |
|
69 | 69 | class RetryOnExceptions(tenacity.retry_if_exception): # type: ignore
|
@@ -581,6 +581,7 @@ def keepalive_mode(self) -> int:
|
581 | 581 | warnings.warn("keepalive_mode was moved to keepalive_period as time based parameter", DeprecationWarning)
|
582 | 582 | return self.keepalive_period
|
583 | 583 |
|
| 584 | + # noinspection PyDeprecation |
584 | 585 | @keepalive_mode.setter
|
585 | 586 | def keepalive_mode(self, period: typing.Union[int, bool]) -> None:
|
586 | 587 | """Keepalive period change for connection object.
|
@@ -641,7 +642,7 @@ def _execute_async( # pylint: disable=arguments-differ
|
641 | 642 | self,
|
642 | 643 | command: str,
|
643 | 644 | *,
|
644 |
| - stdin: _OptStdinT = None, |
| 645 | + stdin: OptionalStdinT = None, |
645 | 646 | open_stdout: bool = True,
|
646 | 647 | open_stderr: bool = True,
|
647 | 648 | chroot_path: typing.Optional[str] = None,
|
@@ -732,11 +733,11 @@ def _exec_command( # type: ignore
|
732 | 733 | self,
|
733 | 734 | command: str,
|
734 | 735 | async_result: SshExecuteAsyncResult,
|
735 |
| - timeout: _OptTimeoutT, |
| 736 | + timeout: OptionalTimeoutT, |
736 | 737 | *,
|
737 | 738 | verbose: bool = False,
|
738 | 739 | log_mask_re: typing.Optional[str] = None,
|
739 |
| - stdin: _OptStdinT = None, |
| 740 | + stdin: OptionalStdinT = None, |
740 | 741 | **kwargs: typing.Any,
|
741 | 742 | ) -> exec_result.ExecResult:
|
742 | 743 | """Get exit status from channel with timeout.
|
@@ -813,10 +814,10 @@ def execute( # pylint: disable=arguments-differ
|
813 | 814 | self,
|
814 | 815 | command: str,
|
815 | 816 | verbose: bool = False,
|
816 |
| - timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT, |
| 817 | + timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT, |
817 | 818 | *,
|
818 | 819 | log_mask_re: typing.Optional[str] = None,
|
819 |
| - stdin: _OptStdinT = None, |
| 820 | + stdin: OptionalStdinT = None, |
820 | 821 | open_stdout: bool = True,
|
821 | 822 | open_stderr: bool = True,
|
822 | 823 | get_pty: bool = False,
|
@@ -874,10 +875,10 @@ def __call__(
|
874 | 875 | self,
|
875 | 876 | command: str,
|
876 | 877 | verbose: bool = False,
|
877 |
| - timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT, |
| 878 | + timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT, |
878 | 879 | *,
|
879 | 880 | log_mask_re: typing.Optional[str] = None,
|
880 |
| - stdin: _OptStdinT = None, |
| 881 | + stdin: OptionalStdinT = None, |
881 | 882 | open_stdout: bool = True,
|
882 | 883 | open_stderr: bool = True,
|
883 | 884 | get_pty: bool = False,
|
@@ -935,19 +936,19 @@ def check_call( # pylint: disable=arguments-differ
|
935 | 936 | self,
|
936 | 937 | command: str,
|
937 | 938 | verbose: bool = False,
|
938 |
| - timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT, |
| 939 | + timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT, |
939 | 940 | error_info: typing.Optional[str] = None,
|
940 |
| - expected: typing.Iterable[_ExitCodeT] = (proc_enums.EXPECTED,), |
| 941 | + expected: typing.Iterable[ExitCodeT] = (proc_enums.EXPECTED,), |
941 | 942 | raise_on_err: bool = True,
|
942 | 943 | *,
|
943 | 944 | log_mask_re: typing.Optional[str] = None,
|
944 |
| - stdin: _OptStdinT = None, |
| 945 | + stdin: OptionalStdinT = None, |
945 | 946 | open_stdout: bool = True,
|
946 | 947 | open_stderr: bool = True,
|
947 | 948 | get_pty: bool = False,
|
948 | 949 | width: int = 80,
|
949 | 950 | height: int = 24,
|
950 |
| - exception_class: "typing.Type[exceptions.CalledProcessError]" = exceptions.CalledProcessError, |
| 951 | + exception_class: CalledProcessErrorSubClassT = exceptions.CalledProcessError, |
951 | 952 | **kwargs: typing.Any,
|
952 | 953 | ) -> exec_result.ExecResult:
|
953 | 954 | """Execute command and check for return code.
|
@@ -1014,19 +1015,19 @@ def check_stderr( # pylint: disable=arguments-differ
|
1014 | 1015 | self,
|
1015 | 1016 | command: str,
|
1016 | 1017 | verbose: bool = False,
|
1017 |
| - timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT, |
| 1018 | + timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT, |
1018 | 1019 | error_info: typing.Optional[str] = None,
|
1019 | 1020 | raise_on_err: bool = True,
|
1020 | 1021 | *,
|
1021 |
| - expected: typing.Iterable[_ExitCodeT] = (proc_enums.EXPECTED,), |
| 1022 | + expected: typing.Iterable[ExitCodeT] = (proc_enums.EXPECTED,), |
1022 | 1023 | log_mask_re: typing.Optional[str] = None,
|
1023 |
| - stdin: _OptStdinT = None, |
| 1024 | + stdin: OptionalStdinT = None, |
1024 | 1025 | open_stdout: bool = True,
|
1025 | 1026 | open_stderr: bool = True,
|
1026 | 1027 | get_pty: bool = False,
|
1027 | 1028 | width: int = 80,
|
1028 | 1029 | height: int = 24,
|
1029 |
| - exception_class: "typing.Type[exceptions.CalledProcessError]" = exceptions.CalledProcessError, |
| 1030 | + exception_class: CalledProcessErrorSubClassT = exceptions.CalledProcessError, |
1030 | 1031 | **kwargs: typing.Any,
|
1031 | 1032 | ) -> exec_result.ExecResult:
|
1032 | 1033 | """Execute command expecting return code 0 and empty STDERR.
|
@@ -1188,8 +1189,8 @@ def execute_through_host(
|
1188 | 1189 | port: typing.Optional[int] = None,
|
1189 | 1190 | target_port: typing.Optional[int] = None,
|
1190 | 1191 | verbose: bool = False,
|
1191 |
| - timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT, |
1192 |
| - stdin: _OptStdinT = None, |
| 1192 | + timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT, |
| 1193 | + stdin: OptionalStdinT = None, |
1193 | 1194 | open_stdout: bool = True,
|
1194 | 1195 | open_stderr: bool = True,
|
1195 | 1196 | log_mask_re: typing.Optional[str] = None,
|
@@ -1270,11 +1271,11 @@ def execute_together(
|
1270 | 1271 | cls,
|
1271 | 1272 | remotes: typing.Iterable["SSHClientBase"],
|
1272 | 1273 | command: str,
|
1273 |
| - timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT, |
1274 |
| - expected: typing.Iterable[_ExitCodeT] = (proc_enums.EXPECTED,), |
| 1274 | + timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT, |
| 1275 | + expected: typing.Iterable[ExitCodeT] = (proc_enums.EXPECTED,), |
1275 | 1276 | raise_on_err: bool = True,
|
1276 | 1277 | *,
|
1277 |
| - stdin: _OptStdinT = None, |
| 1278 | + stdin: OptionalStdinT = None, |
1278 | 1279 | open_stdout: bool = True,
|
1279 | 1280 | open_stderr: bool = True,
|
1280 | 1281 | verbose: bool = False,
|
@@ -1353,7 +1354,7 @@ def get_result(remote: "SSHClientBase") -> exec_result.ExecResult:
|
1353 | 1354 | async_result.interface.close()
|
1354 | 1355 | return res
|
1355 | 1356 |
|
1356 |
| - prep_expected: typing.Sequence[_ExitCodeT] = proc_enums.exit_codes_to_enums(expected) |
| 1357 | + prep_expected: typing.Sequence[ExitCodeT] = proc_enums.exit_codes_to_enums(expected) |
1357 | 1358 | log_level: int = logging.INFO if verbose else logging.DEBUG
|
1358 | 1359 |
|
1359 | 1360 | futures: typing.Dict["SSHClientBase", "concurrent.futures.Future[exec_result.ExecResult]"] = {
|
|
0 commit comments