lib.base.Result.__repr__(): Add method

Add __repr__() to Result to make it more meaningful in log messages.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-06-02 07:26:52 +02:00
commit 6874a90bb4
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -1,7 +1,7 @@
from __future__ import annotations from __future__ import annotations
from enum import Enum, auto from enum import Enum, auto
from typing import NamedTuple, TypeAlias, TYPE_CHECKING from typing import TYPE_CHECKING, NamedTuple, TypeAlias
if TYPE_CHECKING: if TYPE_CHECKING:
import os import os
@ -54,6 +54,23 @@ class Result:
def encoding(self, value: str) -> None: def encoding(self, value: str) -> None:
self.__encoding = value self.__encoding = value
def __stdout_footprint(self, quote = False) -> str:
if self.__stdout is None:
ret = ''
else:
ret = self.stdout_str[:20]
if quote:
ret = '"{ret}"'
return ret
def __repr__(self) -> str:
ret = f'{self.__status}:'
if self.status != 0:
ret += f' err: {self.stderr_str_or_none}'
else:
ret += f' out: {self.__stdout_footprint(quote=True)}'
return ret
@property @property
def strip(self) -> bool: def strip(self) -> bool:
return self.__strip return self.__strip