mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 17:23:36 +02:00
lib.SSHClient: Implement verbose logging
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
e924f34441
commit
37af0a05e9
1 changed files with 19 additions and 5 deletions
|
|
@ -37,22 +37,36 @@ class SSHClient(ExecContext):
|
||||||
log_prefix: str
|
log_prefix: str
|
||||||
) -> Result:
|
) -> Result:
|
||||||
|
|
||||||
def __log(prio, *args, verbose=verbose):
|
def __log(prio: int, *args):
|
||||||
log(prio, log_prefix, *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:
|
if wd is not None:
|
||||||
args = ['cd', wd, '&&', *args]
|
args = ['cd', wd, '&&', *args]
|
||||||
|
|
||||||
if verbose:
|
|
||||||
__log(WARNING, f'Verbose SSH commands are not yet implemented')
|
|
||||||
|
|
||||||
if interactive:
|
if interactive:
|
||||||
raise NotImplementedError('Interactive SSH is not yet implemented')
|
raise NotImplementedError('Interactive SSH is not yet implemented')
|
||||||
|
|
||||||
if env is not None:
|
if env is not None:
|
||||||
raise NotImplementedError('Passing an environment to SSH commands is not yet implemented')
|
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:
|
async def _sudo(self, cmd: list[str], mod_env: dict[str, str], opts: list[str], *args, **kwargs) -> Result:
|
||||||
if self.username != 'root':
|
if self.username != 'root':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue