Skip to content

Commit 99a80ce

Browse files
committed
Expose stdin from **kwargs
Signed-off-by: Aleksei Stepanov <penguinolog@gmail.com> (cherry picked from commit 442ac75) Signed-off-by: Aleksei Stepanov <penguinolog@gmail.com>
1 parent f4bd8cc commit 99a80ce

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

exec_helpers/api.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def execute(
314314
timeout: typing.Union[int, float, None] = constants.DEFAULT_TIMEOUT,
315315
*,
316316
log_mask_re: typing.Optional[str] = None,
317+
stdin: typing.Union[bytes, str, bytearray, None] = None,
317318
**kwargs: typing.Any
318319
) -> exec_result.ExecResult:
319320
"""Execute command and wait for return code.
@@ -327,6 +328,8 @@ def execute(
327328
:param log_mask_re: regex lookup rule to mask command for logger.
328329
all MATCHED groups will be replaced by '<*masked*>'
329330
:type log_mask_re: typing.Optional[str]
331+
:param stdin: pass STDIN text to the process
332+
:type stdin: typing.Union[bytes, str, bytearray, None]
330333
:param kwargs: additional parameters for call.
331334
:type kwargs: typing.Any
332335
:return: Execution result
@@ -337,7 +340,7 @@ def execute(
337340
.. versionchanged:: 2.1.0 Allow parallel calls
338341
"""
339342
async_result = self.execute_async(
340-
command, verbose=verbose, log_mask_re=log_mask_re, **kwargs
343+
command, verbose=verbose, log_mask_re=log_mask_re, stdin=stdin, **kwargs
341344
) # type: ExecuteAsyncResult
342345

343346
result = self._exec_command(
@@ -346,6 +349,7 @@ def execute(
346349
timeout=timeout,
347350
verbose=verbose,
348351
log_mask_re=log_mask_re,
352+
stdin=stdin,
349353
**kwargs
350354
) # type: exec_result.ExecResult
351355
message = "Command {result.cmd!r} exit code: {result.exit_code!s}".format(result=result)
@@ -359,6 +363,7 @@ def __call__(
359363
timeout: typing.Union[int, float, None] = constants.DEFAULT_TIMEOUT,
360364
*,
361365
log_mask_re: typing.Optional[str] = None,
366+
stdin: typing.Union[bytes, str, bytearray, None] = None,
362367
**kwargs: typing.Any
363368
) -> exec_result.ExecResult:
364369
"""Execute command and wait for return code.
@@ -372,6 +377,8 @@ def __call__(
372377
:param log_mask_re: regex lookup rule to mask command for logger.
373378
all MATCHED groups will be replaced by '<*masked*>'
374379
:type log_mask_re: typing.Optional[str]
380+
:param stdin: pass STDIN text to the process
381+
:type stdin: typing.Union[bytes, str, bytearray, None]
375382
:param kwargs: additional parameters for call.
376383
:type kwargs: typing.Any
377384
:return: Execution result
@@ -380,7 +387,9 @@ def __call__(
380387
381388
.. versionadded:: 2.9.4
382389
"""
383-
return self.execute(command=command, verbose=verbose, timeout=timeout, log_mask_re=log_mask_re, **kwargs)
390+
return self.execute(
391+
command=command, verbose=verbose, timeout=timeout, log_mask_re=log_mask_re, stdin=stdin, **kwargs
392+
)
384393

385394
def check_call(
386395
self,
@@ -392,6 +401,7 @@ def check_call(
392401
raise_on_err: bool = True,
393402
*,
394403
log_mask_re: typing.Optional[str] = None,
404+
stdin: typing.Union[bytes, str, bytearray, None] = None,
395405
exception_class: "typing.Type[exceptions.CalledProcessError]" = exceptions.CalledProcessError,
396406
**kwargs: typing.Any
397407
) -> exec_result.ExecResult:
@@ -412,6 +422,8 @@ def check_call(
412422
:param log_mask_re: regex lookup rule to mask command for logger.
413423
all MATCHED groups will be replaced by '<*masked*>'
414424
:type log_mask_re: typing.Optional[str]
425+
:param stdin: pass STDIN text to the process
426+
:type stdin: typing.Union[bytes, str, bytearray, None]
415427
:param exception_class: Exception class for errors. Subclass of CalledProcessError is mandatory.
416428
:type exception_class: typing.Type[exceptions.CalledProcessError]
417429
:param kwargs: additional parameters for call.
@@ -427,7 +439,8 @@ def check_call(
427439
"""
428440
expected_codes = proc_enums.exit_codes_to_enums(expected)
429441
result = self.execute(
430-
command, verbose, timeout, log_mask_re=log_mask_re, **kwargs
442+
command, verbose, timeout, log_mask_re=log_mask_re, stdin=stdin, **kwargs
443+
431444
) # type: exec_result.ExecResult
432445
if result.exit_code not in expected_codes:
433446
message = (
@@ -449,8 +462,9 @@ def check_stderr(
449462
error_info: typing.Optional[str] = None,
450463
raise_on_err: bool = True,
451464
*,
452-
log_mask_re: typing.Optional[str] = None,
453465
expected: typing.Iterable[typing.Union[int, proc_enums.ExitCodes]] = (proc_enums.EXPECTED,),
466+
log_mask_re: typing.Optional[str] = None,
467+
stdin: typing.Union[bytes, str, bytearray, None] = None,
454468
exception_class: "typing.Type[exceptions.CalledProcessError]" = exceptions.CalledProcessError,
455469
**kwargs: typing.Any
456470
) -> exec_result.ExecResult:
@@ -466,11 +480,13 @@ def check_stderr(
466480
:type error_info: typing.Optional[str]
467481
:param raise_on_err: Raise exception on unexpected return code
468482
:type raise_on_err: bool
483+
:param expected: expected return codes (0 by default)
484+
:type expected: typing.Iterable[typing.Union[int, proc_enums.ExitCodes]]
469485
:param log_mask_re: regex lookup rule to mask command for logger.
470486
all MATCHED groups will be replaced by '<*masked*>'
471487
:type log_mask_re: typing.Optional[str]
472-
:param expected: expected return codes (0 by default)
473-
:type expected: typing.Iterable[typing.Union[int, proc_enums.ExitCodes]]
488+
:param stdin: pass STDIN text to the process
489+
:type stdin: typing.Union[bytes, str, bytearray, None]
474490
:param exception_class: Exception class for errors. Subclass of CalledProcessError is mandatory.
475491
:type exception_class: typing.Type[exceptions.CalledProcessError]
476492
:param kwargs: additional parameters for call.
@@ -493,6 +509,7 @@ def check_stderr(
493509
expected=expected,
494510
exception_class=exception_class,
495511
log_mask_re=log_mask_re,
512+
stdin=stdin,
496513
**kwargs
497514
)
498515
append = error_info + "\n" if error_info else "" # type: str

0 commit comments

Comments
 (0)