Skip to content

Commit 09e2c36

Browse files
committed
Allow to not log stdout/stderr during reading
1 parent 8a4e7b4 commit 09e2c36

File tree

8 files changed

+260
-15
lines changed

8 files changed

+260
-15
lines changed

README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Pros:
4646
Python 3.7
4747
Python 3.8
4848
Python 3.9
49+
Python 3.10
4950

5051
.. note:: Old pythons: For Python 2.7 and PyPy use versions 1.x.x, python 3.4 use versions 2.x.x, python 3.5 and PyPy 3.5 use versions 3.x.x
5152

@@ -147,7 +148,9 @@ This methods are almost the same for `SSHClient` and `Subprocess`, except specif
147148
log_mask_re=None, # type: Optional[str]
148149
stdin=None, # type: Union[bytes, str, bytearray, None]
149150
open_stdout=True, # type: bool
151+
log_stdout=True, # type: bool
150152
open_stderr=True, # type: bool
153+
log_stderr=True, # type: bool
151154
**kwargs
152155
)
153156
@@ -165,7 +168,9 @@ This methods are almost the same for `SSHClient` and `Subprocess`, except specif
165168
log_mask_re=None, # type: Optional[str]
166169
stdin=None, # type: Union[bytes, str, bytearray, None]
167170
open_stdout=True, # type: bool
171+
log_stdout=True, # type: bool
168172
open_stderr=True, # type: bool
173+
log_stderr=True, # type: bool
169174
exception_class=CalledProcessError, # Type[CalledProcessError]
170175
**kwargs
171176
)
@@ -183,7 +188,9 @@ This methods are almost the same for `SSHClient` and `Subprocess`, except specif
183188
log_mask_re=None, # type: Optional[str]
184189
stdin=None, # type: Union[bytes, str, bytearray, None]
185190
open_stdout=True, # type: bool
191+
log_stdout=True, # type: bool
186192
open_stderr=True, # type: bool
193+
log_stderr=True, # type: bool
187194
exception_class=CalledProcessError, # Type[CalledProcessError]
188195
)
189196
@@ -197,7 +204,9 @@ This methods are almost the same for `SSHClient` and `Subprocess`, except specif
197204
log_mask_re=None, # type: Optional[str]
198205
stdin=None, # type: Union[bytes, str, bytearray, None]
199206
open_stdout=True, # type: bool
207+
log_stdout=True, # type: bool
200208
open_stderr=True, # type: bool
209+
log_stderr=True, # type: bool
201210
**kwargs
202211
)
203212
@@ -305,7 +314,9 @@ For execute through SSH host can be used `execute_through_host` method:
305314
verbose=False, # type: bool
306315
stdin=None, # type: Union[bytes, str, bytearray, None]
307316
open_stdout=True, # type: bool
317+
log_stdout=True, # type: bool
308318
open_stderr=True, # type: bool
319+
log_stderr=True, # type: bool
309320
log_mask_re=None, # type: Optional[str]
310321
get_pty=False, # type: bool
311322
width=80, # type: int

doc/source/SSHClient.rst

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ API: SSHClient and SSHAuth.
150150
.. Note:: Enter and exit ssh context manager is produced as well.
151151
.. versionadded:: 1.2.1
152152

153-
.. py:method:: execute(command, verbose=False, timeout=1*60*60, *, log_mask_re=None, stdin=None, open_stdout=True, open_stderr=True, get_pty=False, width=80, height=24, **kwargs)
153+
.. py:method:: execute(command, verbose=False, timeout=1*60*60, *, log_mask_re=None, stdin=None, open_stdout=True, log_stdout = True, open_stderr=True, log_stderr = True, get_pty=False, width=80, height=24, **kwargs)
154154
155155
Execute command and wait for return code.
156156

@@ -166,8 +166,12 @@ API: SSHClient and SSHAuth.
166166
:type stdin: ``Union[bytes, str, bytearray, None]``
167167
:param open_stdout: open STDOUT stream for read
168168
:type open_stdout: ``bool``
169+
:param log_stdout: log STDOUT during read
170+
:type log_stdout: ``bool``
169171
:param open_stderr: open STDERR stream for read
170172
:type open_stderr: ``bool``
173+
:param log_stderr: log STDERR during read
174+
:type log_stderr: ``bool``
171175
:param get_pty: Get PTY for connection
172176
:type get_pty: ``bool``
173177
:param width: PTY width
@@ -179,7 +183,7 @@ API: SSHClient and SSHAuth.
179183

180184
.. versionchanged:: 1.2.0 default timeout 1 hour
181185

182-
.. py:method:: __call__(command, verbose=False, timeout=1*60*60, *, log_mask_re=None, stdin=None, open_stdout=True, open_stderr=True, get_pty=False, width=80, height=24, **kwargs)
186+
.. py:method:: __call__(command, verbose=False, timeout=1*60*60, *, log_mask_re=None, stdin=None, open_stdout=True, log_stdout = True, open_stderr=True, log_stderr = True, get_pty=False, width=80, height=24, **kwargs)
183187
184188
Execute command and wait for return code.
185189

@@ -195,8 +199,12 @@ API: SSHClient and SSHAuth.
195199
:type stdin: ``Union[bytes, str, bytearray, None]``
196200
:param open_stdout: open STDOUT stream for read
197201
:type open_stdout: ``bool``
202+
:param log_stdout: log STDOUT during read
203+
:type log_stdout: ``bool``
198204
:param open_stderr: open STDERR stream for read
199205
:type open_stderr: ``bool``
206+
:param log_stderr: log STDERR during read
207+
:type log_stderr: ``bool``
200208
:param get_pty: Get PTY for connection
201209
:type get_pty: ``bool``
202210
:param width: PTY width
@@ -208,7 +216,7 @@ API: SSHClient and SSHAuth.
208216

209217
.. versionadded:: 3.3.0
210218

211-
.. py:method:: check_call(command, verbose=False, timeout=1*60*60, error_info=None, expected=(0,), raise_on_err=True, *, log_mask_re=None, stdin=None, open_stdout=True, open_stderr=True, get_pty=False, width=80, height=24, exception_class=CalledProcessError, **kwargs)
219+
.. py:method:: check_call(command, verbose=False, timeout=1*60*60, error_info=None, expected=(0,), raise_on_err=True, *, log_mask_re=None, stdin=None, open_stdout=True, log_stdout = True, open_stderr=True, log_stderr = True, get_pty=False, width=80, height=24, exception_class=CalledProcessError, **kwargs)
212220
213221
Execute command and check for return code.
214222

@@ -230,8 +238,12 @@ API: SSHClient and SSHAuth.
230238
:type stdin: ``Union[bytes, str, bytearray, None]``
231239
:param open_stdout: open STDOUT stream for read
232240
:type open_stdout: ``bool``
241+
:param log_stdout: log STDOUT during read
242+
:type log_stdout: ``bool``
233243
:param open_stderr: open STDERR stream for read
234244
:type open_stderr: ``bool``
245+
:param log_stderr: log STDERR during read
246+
:type log_stderr: ``bool``
235247
:param get_pty: Get PTY for connection
236248
:type get_pty: ``bool``
237249
:param width: PTY width
@@ -248,7 +260,7 @@ API: SSHClient and SSHAuth.
248260
.. versionchanged:: 3.2.0 Exception class can be substituted
249261
.. versionchanged:: 3.4.0 Expected is not optional, defaults os dependent
250262

251-
.. py:method:: check_stderr(command, verbose=False, timeout=1*60*60, error_info=None, raise_on_err=True, *, expected=(0,), log_mask_re=None, stdin=None, open_stdout=True, open_stderr=True, get_pty=False, width=80, height=24, exception_class=CalledProcessError, **kwargs)
263+
.. py:method:: check_stderr(command, verbose=False, timeout=1*60*60, error_info=None, raise_on_err=True, *, expected=(0,), log_mask_re=None, stdin=None, open_stdout=True, log_stdout = True, open_stderr=True, log_stderr = True, get_pty=False, width=80, height=24, exception_class=CalledProcessError, **kwargs)
252264
253265
Execute command expecting return code 0 and empty STDERR.
254266

@@ -270,8 +282,12 @@ API: SSHClient and SSHAuth.
270282
:type stdin: ``Union[bytes, str, bytearray, None]``
271283
:param open_stdout: open STDOUT stream for read
272284
:type open_stdout: ``bool``
285+
:param log_stdout: log STDOUT during read
286+
:type log_stdout: ``bool``
273287
:param open_stderr: open STDERR stream for read
274288
:type open_stderr: ``bool``
289+
:param log_stderr: log STDERR during read
290+
:type log_stderr: ``bool``
275291
:param get_pty: Get PTY for connection
276292
:type get_pty: ``bool``
277293
:param width: PTY width
@@ -316,7 +332,7 @@ API: SSHClient and SSHAuth.
316332

317333
.. versionadded:: 6.0.0
318334

319-
.. py:method:: execute_through_host(hostname, command, *, auth=None, port=22, verbose=False, timeout=1*60*60, stdin=None, open_stdout=True, open_stderr=True, log_mask_re="", get_pty=False, width=80, height=24, **kwargs)
335+
.. py:method:: execute_through_host(hostname, command, *, auth=None, port=22, verbose=False, timeout=1*60*60, stdin=None, open_stdout=True, log_stdout = True, open_stderr=True, log_stderr = True, log_mask_re="", get_pty=False, width=80, height=24, **kwargs)
320336
321337
Execute command on remote host through currently connected host.
322338

@@ -336,8 +352,12 @@ API: SSHClient and SSHAuth.
336352
:type stdin: ``Union[bytes, str, bytearray, None]``
337353
:param open_stdout: open STDOUT stream for read
338354
:type open_stdout: ``bool``
355+
:param log_stdout: log STDOUT during read
356+
:type log_stdout: ``bool``
339357
:param open_stderr: open STDERR stream for read
340358
:type open_stderr: ``bool``
359+
:param log_stderr: log STDERR during read
360+
:type log_stderr: ``bool``
341361
:param log_mask_re: regex lookup rule to mask command for logger. all MATCHED groups will be replaced by '<*masked*>'
342362
:type log_mask_re: ``Optional[str]``
343363
:param get_pty: open PTY on target machine

doc/source/Subprocess.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ API: Subprocess
5555
.. Note:: Enter and exit main context manager is produced as well.
5656
.. versionadded:: 4.1.0
5757

58-
.. py:method:: execute(command, verbose=False, timeout=1*60*60, *, log_mask_re=None, stdin=None, open_stdout=True, open_stderr=True, cwd=None, env=None, env_patch=None, **kwargs)
58+
.. py:method:: execute(command, verbose=False, timeout=1*60*60, *, log_mask_re=None, stdin=None, open_stdout=True, log_stdout = True, open_stderr=True, log_stderr = True, cwd=None, env=None, env_patch=None, **kwargs)
5959
6060
Execute command and wait for return code.
6161

@@ -72,8 +72,12 @@ API: Subprocess
7272
:type stdin: ``Union[bytes, str, bytearray, None]``
7373
:param open_stdout: open STDOUT stream for read
7474
:type open_stdout: ``bool``
75+
:param log_stdout: log STDOUT during read
76+
:type log_stdout: ``bool``
7577
:param open_stderr: open STDERR stream for read
7678
:type open_stderr: ``bool``
79+
:param log_stderr: log STDERR during read
80+
:type log_stderr: ``bool``
7781
:param cwd: Sets the current directory before the child is executed.
7882
:type cwd: ``Optional[Union[str, bytes, pathlib.Path]]``
7983
:param env: Defines the environment variables for the new process.
@@ -89,7 +93,7 @@ API: Subprocess
8993
.. versionchanged:: 1.2.0 default timeout 1 hour
9094
.. versionchanged:: 1.2.0 stdin data
9195

92-
.. py:method:: __call__(command, verbose=False, timeout=1*60*60, *, log_mask_re=None, stdin=None, open_stdout=True, open_stderr=True, cwd=None, env=None, env_patch=None, **kwargs)
96+
.. py:method:: __call__(command, verbose=False, timeout=1*60*60, *, log_mask_re=None, stdin=None, open_stdout=True, log_stdout = True, open_stderr=True, log_stderr = True, cwd=None, env=None, env_patch=None, **kwargs)
9397
9498
Execute command and wait for return code.
9599

@@ -106,8 +110,12 @@ API: Subprocess
106110
:type stdin: ``Union[bytes, str, bytearray, None]``
107111
:param open_stdout: open STDOUT stream for read
108112
:type open_stdout: ``bool``
113+
:param log_stdout: log STDOUT during read
114+
:type log_stdout: ``bool``
109115
:param open_stderr: open STDERR stream for read
110116
:type open_stderr: ``bool``
117+
:param log_stderr: log STDERR during read
118+
:type log_stderr: ``bool``
111119
:param cwd: Sets the current directory before the child is executed.
112120
:type cwd: ``Optional[Union[str, bytes, pathlib.Path]]``
113121
:param env: Defines the environment variables for the new process.
@@ -120,7 +128,7 @@ API: Subprocess
120128
.. note:: stdin channel is closed after the input processing
121129
.. versionadded:: 3.3.0
122130

123-
.. py:method:: check_call(command, verbose=False, timeout=1*60*60, error_info=None, expected=(0,), raise_on_err=True, *, log_mask_re=None, stdin=None, open_stdout=True, open_stderr=True, cwd=None, env=None, env_patch=None, exception_class=CalledProcessError, **kwargs)
131+
.. py:method:: check_call(command, verbose=False, timeout=1*60*60, error_info=None, expected=(0,), raise_on_err=True, *, log_mask_re=None, stdin=None, open_stdout=True, log_stdout = True, open_stderr=True, log_stderr = True, cwd=None, env=None, env_patch=None, exception_class=CalledProcessError, **kwargs)
124132
125133
Execute command and check for return code.
126134

@@ -143,8 +151,12 @@ API: Subprocess
143151
:type stdin: ``Union[bytes, str, bytearray, None]``
144152
:param open_stdout: open STDOUT stream for read
145153
:type open_stdout: ``bool``
154+
:param log_stdout: log STDOUT during read
155+
:type log_stdout: ``bool``
146156
:param open_stderr: open STDERR stream for read
147157
:type open_stderr: ``bool``
158+
:param log_stderr: log STDERR during read
159+
:type log_stderr: ``bool``
148160
:param cwd: Sets the current directory before the child is executed.
149161
:type cwd: ``Optional[Union[str, bytes, pathlib.Path]]``
150162
:param env: Defines the environment variables for the new process.
@@ -162,7 +174,7 @@ API: Subprocess
162174
.. versionchanged:: 3.2.0 Exception class can be substituted
163175
.. versionchanged:: 3.4.0 Expected is not optional, defaults os dependent
164176

165-
.. py:method:: check_stderr(command, verbose=False, timeout=1*60*60, error_info=None, raise_on_err=True, *, expected=(0,), log_mask_re=None, stdin=None, open_stdout=True, open_stderr=True, cwd=None, env=None, env_patch=None, exception_class=CalledProcessError, **kwargs)
177+
.. py:method:: check_stderr(command, verbose=False, timeout=1*60*60, error_info=None, raise_on_err=True, *, expected=(0,), log_mask_re=None, stdin=None, open_stdout=True, log_stdout = True, open_stderr=True, log_stderr = True, cwd=None, env=None, env_patch=None, exception_class=CalledProcessError, **kwargs)
166178
167179
Execute command expecting return code 0 and empty STDERR.
168180

@@ -185,8 +197,12 @@ API: Subprocess
185197
:type stdin: ``Union[bytes, str, bytearray, None]``
186198
:param open_stdout: open STDOUT stream for read
187199
:type open_stdout: ``bool``
200+
:param log_stdout: log STDOUT during read
201+
:type log_stdout: ``bool``
188202
:param open_stderr: open STDERR stream for read
189203
:type open_stderr: ``bool``
204+
:param log_stderr: log STDERR during read
205+
:type log_stderr: ``bool``
190206
:param cwd: Sets the current directory before the child is executed.
191207
:type cwd: ``Optional[Union[str, bytes, pathlib.Path]]``
192208
:param env: Defines the environment variables for the new process.

0 commit comments

Comments
 (0)