Added format_function_output()
This commit is contained in:
parent
ff4e371b32
commit
4e5bef23da
1 changed files with 27 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from subprocess import CompletedProcess
|
||||||
try:
|
try:
|
||||||
from termios import tcflush, TCIOFLUSH
|
from termios import tcflush, TCIOFLUSH
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
@ -164,8 +165,32 @@ def format_exception_message(_exception, indent=INDENT, width=WIDTH):
|
||||||
|
|
||||||
|
|
||||||
def format_function_output(output, indent=INDENT, width=WIDTH):
|
def format_function_output(output, indent=INDENT, width=WIDTH):
|
||||||
"""TODO"""
|
"""Format function output for use in try_and_print(), returns str."""
|
||||||
return 'TODO'
|
LOG.debug('formatting output: %s', output)
|
||||||
|
|
||||||
|
# Ensure we're working with a list
|
||||||
|
if isinstance(output, CompletedProcess):
|
||||||
|
stdout = output.stdout
|
||||||
|
if not isinstance(stdout, str):
|
||||||
|
stdout = stdout.decode('utf8')
|
||||||
|
output = stdout.strip().splitlines()
|
||||||
|
else:
|
||||||
|
output = list(output)
|
||||||
|
|
||||||
|
# Safety check
|
||||||
|
if not output:
|
||||||
|
# Going to ignore empty function output for now
|
||||||
|
LOG.error('Output is empty')
|
||||||
|
return 'UNKNOWN'
|
||||||
|
|
||||||
|
# Build result_msg
|
||||||
|
result_msg = f'{output.pop(0)}'
|
||||||
|
if output:
|
||||||
|
output = [f'{" "*(indent+width)}{line}' for line in output]
|
||||||
|
result_msg += '\n' + '\n'.join(output)
|
||||||
|
|
||||||
|
# Done
|
||||||
|
return result_msg
|
||||||
|
|
||||||
|
|
||||||
def get_exception(name):
|
def get_exception(name):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue