Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
#57: Added additional documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Nov 11, 2020
1 parent 4fabe00 commit 04e4e1f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/rkd/process.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/usr/bin/env python3

"""
Process
=======
Library that wraps standard "subprocess" library, adding a correct output capturing capabilities.
By default standard "subprocess" library writes directly to descriptors, bypassing sys.stdout and sys.stderr
making it impossible to capture the text for logging.
"""

import os
import sys
import subprocess
Expand Down Expand Up @@ -50,6 +60,15 @@ def __init__(self):


def check_call(command: str, script_to_show: Optional[str] = ''):
"""
Another implementation of subprocess.check_call(), in comparison - this method writes output directly to
sys.stdout and sys.stderr, which makes output capturing possible
:param command: Command to execute
:param script_to_show: Command to show that it failed
:return:
"""

if os.getenv('RKD_COMPAT_SUBPROCESS') == 'true':
subprocess.check_call(command, shell=True)
return
Expand Down Expand Up @@ -92,7 +111,9 @@ def check_call(command: str, script_to_show: Optional[str] = ''):

if exit_code > 0:
raise subprocess.CalledProcessError(
exit_code, script_to_show if script_to_show else command, stderr=out_buffer.get_value(), output=out_buffer.get_value()
exit_code, script_to_show if script_to_show else command,
stderr=out_buffer.get_value(),
output=out_buffer.get_value()
)


Expand Down

0 comments on commit 04e4e1f

Please sign in to comment.