mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 17:23:36 +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,14 +81,20 @@ async def run_cmd(
|
||||||
if not ret:
|
if not ret:
|
||||||
return ret
|
return ret
|
||||||
collector.append(ret)
|
collector.append(ret)
|
||||||
if verbose:
|
|
||||||
__log(NOTICE, ret.decode(enc_for_verbose, errors="replace").rstrip("\n"))
|
|
||||||
return ret
|
return ret
|
||||||
return _read
|
return _read
|
||||||
|
|
||||||
|
interactive = (
|
||||||
|
cmd_input == "mode:interactive"
|
||||||
|
or (cmd_input == "mode:auto" and sys.stdin.isatty())
|
||||||
|
)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
delim_len = 120
|
delim_len = 120
|
||||||
delim = title if title is not None else f'---- Running {pretty_cmd(args, wd)} -'
|
delim = title if title is not None else f'---- Running {pretty_cmd(args, wd)} -'
|
||||||
|
if interactive:
|
||||||
|
log(NOTICE, delim)
|
||||||
|
else:
|
||||||
delim += '-' * max(0, delim_len - len(delim))
|
delim += '-' * max(0, delim_len - len(delim))
|
||||||
log(NOTICE, ',' + delim + ' >')
|
log(NOTICE, ',' + delim + ' >')
|
||||||
|
|
||||||
|
|
@ -100,10 +106,8 @@ async def run_cmd(
|
||||||
try:
|
try:
|
||||||
|
|
||||||
# -- interactive mode
|
# -- interactive mode
|
||||||
if cmd_input == "mode:auto" and sys.stdin.isatty():
|
|
||||||
cmd_input = "mode:interactive"
|
|
||||||
|
|
||||||
if cmd_input == "mode:interactive":
|
if interactive:
|
||||||
|
|
||||||
import pty
|
import pty
|
||||||
|
|
||||||
|
|
@ -219,7 +223,7 @@ async def run_cmd(
|
||||||
finally:
|
finally:
|
||||||
if cwd is not None:
|
if cwd is not None:
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
if verbose:
|
if verbose and not interactive:
|
||||||
log(NOTICE, '`' + delim + ' <')
|
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
|
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