mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 17:45:55 +02:00
lib.util.run_cmd(): Reduce interactive logging
run_cmd() with cmd_input == mode:interactive and verbose == true logs output too often. First, __log() is called, then pty.spawn() writes everything it reads from the PTY master to the terminal. The fix it to not call __log() from _read() for the PTY reader. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
e322629ac1
commit
0c1c2b9351
1 changed files with 12 additions and 8 deletions
|
|
@ -81,16 +81,22 @@ async def run_cmd(
|
|||
if not ret:
|
||||
return ret
|
||||
collector.append(ret)
|
||||
if verbose:
|
||||
__log(NOTICE, ret.decode(enc_for_verbose, errors="replace").rstrip("\n"))
|
||||
return ret
|
||||
return _read
|
||||
|
||||
interactive = (
|
||||
cmd_input == "mode:interactive"
|
||||
or (cmd_input == "mode:auto" and sys.stdin.isatty())
|
||||
)
|
||||
|
||||
if verbose:
|
||||
delim_len = 120
|
||||
delim = title if title is not None else f'---- Running {pretty_cmd(args, wd)} -'
|
||||
delim += '-' * max(0, delim_len - len(delim))
|
||||
log(NOTICE, ',' + delim + ' >')
|
||||
if interactive:
|
||||
log(NOTICE, delim)
|
||||
else:
|
||||
delim += '-' * max(0, delim_len - len(delim))
|
||||
log(NOTICE, ',' + delim + ' >')
|
||||
|
||||
cwd: str|None = None
|
||||
if wd is not None:
|
||||
|
|
@ -100,10 +106,8 @@ async def run_cmd(
|
|||
try:
|
||||
|
||||
# -- interactive mode
|
||||
if cmd_input == "mode:auto" and sys.stdin.isatty():
|
||||
cmd_input = "mode:interactive"
|
||||
|
||||
if cmd_input == "mode:interactive":
|
||||
if interactive:
|
||||
|
||||
import pty
|
||||
|
||||
|
|
@ -219,7 +223,7 @@ async def run_cmd(
|
|||
finally:
|
||||
if cwd is not None:
|
||||
os.chdir(cwd)
|
||||
if verbose:
|
||||
if verbose and not interactive:
|
||||
log(NOTICE, '`' + delim + ' <')
|
||||
|
||||
async def run_curl(args: list[str], parse_json: bool=True, wd=None, throw=None, verbose=False, cmd_input=None) -> dict|str: # export
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue