From 00b149d870be83ca811336f0fe7d7179ff2a6e15 Mon Sep 17 00:00:00 2001 From: Zapta Date: Sun, 13 Oct 2024 21:22:00 -0700 Subject: [PATCH] Fixing a regression from commit 93fc9bc4f3bfd21568e2d66f11976831467e3b97. Now that we preserve empty stdout/err lines from scons pipes, we need to erase for the iceprog progress percentage two lines instead of one. I don't have Fumo and Tinyprog boards to test if this affect them as well so added TODOs to test and apply the same change if needed. Alhambra II upload (Iceprog) was tested successfuly. --- apio/managers/scons.py | 4 ++++ apio/managers/scons_filter.py | 41 +++++++++++++++++++++++++++-------- apio/util.py | 4 ++-- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/apio/managers/scons.py b/apio/managers/scons.py index 8c665e31..13c23ef5 100644 --- a/apio/managers/scons.py +++ b/apio/managers/scons.py @@ -60,6 +60,10 @@ def wrapper(*args, **kwargs): try: return function(*args, **kwargs) except Exception as exc: + # For debugging. Uncomment to print the exception's stack. + # import traceback + # traceback.print_tb(exc.__traceback__) + if str(exc): click.secho("Error: " + str(exc), fg="red") return exit_code diff --git a/apio/managers/scons_filter.py b/apio/managers/scons_filter.py index 8b484879..d33a3989 100644 --- a/apio/managers/scons_filter.py +++ b/apio/managers/scons_filter.py @@ -164,10 +164,10 @@ def on_line(self, pipe_id: PipeId, line: str) -> None: # -- Assign line color. line_color = self._assign_line_color( line.lower(), - { + [ (r"^warning:", "yellow"), (r"^error:", "red"), - }, + ], ) click.secho(f"{line}", fg=line_color) return @@ -178,8 +178,16 @@ def on_line(self, pipe_id: PipeId, line: str) -> None: match = re.search(pattern_fomu, line) if match: # -- Delete the previous line + # + # -- TODO: Since the commit listed below we preserve blank + # -- stdour/err lines. Iceprog emits an empty line after each + # -- percentage line so we changed it below to erase two lines. + # -- If this is also the case with tinyprog, apply the same + # -- change here. Delete this TODO when resolved. + # - Comit 93fc9bc4f3bfd21568e2d66f11976831467e3b97. + # print(CURSOR_UP + ERASE_LINE, end="", flush=True) - click.secho(f"{line}", fg="green") + click.secho(line, fg="green") return # -- Special handling for tinyprog lines. @@ -198,9 +206,17 @@ def on_line(self, pipe_id: PipeId, line: str) -> None: # -- Match all the progress bar lines except the # -- initial one (when it is 0%) if match_tinyprog and " 0%|" not in line: - # -- Delete the previous line + # -- Delete the previous line. + # + # -- TODO: Since the commit listed below we preserve blank + # -- stdour/err lines. Iceprog emits an empty line after each + # -- percentage line so we changed it below to erase two lines. + # -- If this is also the case with tinyprog, apply the same + # -- change here. Delete this TODO when resolved. + # - Comit 93fc9bc4f3bfd21568e2d66f11976831467e3b97. + # print(CURSOR_UP + ERASE_LINE, end="", flush=True) - click.secho(f"{line}") + click.secho(line) return # -- Special handling for iceprog lines. @@ -219,10 +235,17 @@ def on_line(self, pipe_id: PipeId, line: str) -> None: # -- It is a match! (iceprog is running!) # -- (or if it is the end of the writing!) # -- (or if it is the end of verifying!) - if match or "done." in line or "VERIFY OK" in line: - # -- Delete the previous line - print(CURSOR_UP + ERASE_LINE, end="", flush=True) - click.secho(line) + completed_ok = "done." in line or "VERIFY OK" in line + if match or completed_ok: + # -- Delete the previous two lines. We erase two lines because + # -- iceprog emits an empty line after each percentage line. + print( + CURSOR_UP + ERASE_LINE + CURSOR_UP + ERASE_LINE, + end="", + flush=True, + ) + line_color = "green" if completed_ok else None + click.secho(line, fg=line_color) return # Handling the rest of the stdout lines. diff --git a/apio/util.py b/apio/util.py index 2009f69d..055c7162 100644 --- a/apio/util.py +++ b/apio/util.py @@ -686,14 +686,14 @@ def exec_command(*args, **kwargs) -> CommandResult: if isinstance(pipe, AsyncPipe): lines = pipe.get_buffer() text = "\n".join(lines) - out_text = text.strip() + out_text = text # -- If stderr pipe is an AsyncPipe, extract its text. pipe = flags["stderr"] if isinstance(pipe, AsyncPipe): lines = pipe.get_buffer() text = "\n".join(lines) - err_text = text.strip() + err_text = text # -- All done. result = CommandResult(out_text, err_text, exit_code)