From 37af0a05e9053ee54f3e81106c0a6d1002848137 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Thu, 19 Mar 2026 07:13:12 +0100 Subject: [PATCH] lib.SSHClient: Implement verbose logging Signed-off-by: Jan Lindemann --- src/python/jw/pkg/lib/SSHClient.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/python/jw/pkg/lib/SSHClient.py b/src/python/jw/pkg/lib/SSHClient.py index 6df72e26..c9190aa2 100644 --- a/src/python/jw/pkg/lib/SSHClient.py +++ b/src/python/jw/pkg/lib/SSHClient.py @@ -37,22 +37,36 @@ class SSHClient(ExecContext): log_prefix: str ) -> Result: - def __log(prio, *args, verbose=verbose): + def __log(prio: int, *args): log(prio, log_prefix, *args) + def __log_block(prio: int, title: str, block: str): + encoding = sys.stdout.encoding or 'utf-8' + block = block.decode(encoding).strip() + if not block: + return + delim = f'---- {title} ----' + __log(prio, f',{delim}') + for line in block.splitlines(): + __log(prio, '|', line) + __log(prio, f'`{delim}') + if wd is not None: args = ['cd', wd, '&&', *args] - if verbose: - __log(WARNING, f'Verbose SSH commands are not yet implemented') - if interactive: raise NotImplementedError('Interactive SSH is not yet implemented') if env is not None: raise NotImplementedError('Passing an environment to SSH commands is not yet implemented') - return await self._run_ssh(args, cmd_input=cmd_input) + ret = await self._run_ssh(args, cmd_input=cmd_input) + if verbose: + __log_block(NOTICE, 'stdout', ret.stdout) + __log_block(NOTICE, 'stderr', ret.stderr) + if ret.status != 0: + __log(WARNING, f'Exit code {ret.status}') + return ret async def _sudo(self, cmd: list[str], mod_env: dict[str, str], opts: list[str], *args, **kwargs) -> Result: if self.username != 'root':