Skip to content

Commit

Permalink
Fixing a regression from commit 93fc9bc. Now that we preserve empty s…
Browse files Browse the repository at this point in the history
…tdout/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.
  • Loading branch information
zapta committed Oct 14, 2024
1 parent dd102ac commit 00b149d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
4 changes: 4 additions & 0 deletions apio/managers/scons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 32 additions & 9 deletions apio/managers/scons_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions apio/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 00b149d

Please sign in to comment.