Implement basic version of ssh shell

Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
This commit is contained in:
Vladimir Domnich 2022-08-24 15:41:11 +04:00 committed by anastasia prasolova
parent f6ee129354
commit d3e5ee2231
16 changed files with 525 additions and 92 deletions

View file

@ -1,9 +1,30 @@
import traceback
from shell.interfaces import CommandResult
def format_error_details(error: Exception) -> str:
return "".join(traceback.format_exception(
"""
Converts specified exception instance into a string that includes error message
and full stack trace.
:param Exception error: exception to convert.
:return: string containing exception details.
"""
detail_lines = traceback.format_exception(
etype=type(error),
value=error,
tb=error.__traceback__)
tb=error.__traceback__,
)
return "".join(detail_lines)
def get_output_lines(result: CommandResult) -> list[str]:
"""
Converts output of specified command result into separate lines trimmed from whitespaces.
Empty lines are excluded.
:param CommandResult result: result which output should be converted.
:return: list of lines extracted from the output.
"""
return [line.strip() for line in result.stdout.split("\n") if line.strip()]