Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import tqdm
import spotipy

from utils.progress_line import parse_progress_line
from utils.progress_line import is_blank_console_line, parse_progress_line

# --- CORRECCIÓN DE CODIFICACIÓN PARA EMOJIS EN WINDOWS ---
if sys.stdout is not None and hasattr(sys.stdout, 'reconfigure'):
Expand Down Expand Up @@ -331,6 +331,9 @@ def _append():
self.progress_bar.set(percent / 100)
return

if is_blank_console_line(text):
return

self.log_textbox.configure(state="normal")
self.log_textbox.insert("end", text)
self.log_textbox.configure(state="disabled")
Expand Down
20 changes: 18 additions & 2 deletions tests/test_progress_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if project_root not in sys.path:
sys.path.append(project_root)

from utils.progress_line import parse_progress_line
from utils.progress_line import is_blank_console_line, parse_progress_line


def test_plain_progress_line_is_recognised():
Expand Down Expand Up @@ -42,13 +42,27 @@ def test_non_numeric_progress_is_not_recognised():

def test_empty_input_is_not_recognised():
assert parse_progress_line("") is None
assert parse_progress_line(None) is None # type: ignore[arg-type]
assert parse_progress_line(None) is None


def test_plain_log_line_is_passed_through():
assert parse_progress_line("Doing stuff\n") is None


def test_blank_console_line_is_suppressed():
assert is_blank_console_line("")
assert is_blank_console_line("\n")
assert is_blank_console_line("\r")
assert is_blank_console_line("\r\n")
assert is_blank_console_line(" \r\n")
assert is_blank_console_line(None)


def test_non_blank_console_line_is_not_suppressed():
assert not is_blank_console_line("Processing tracks\n")
assert not is_blank_console_line(" PROG:50\n")


if __name__ == "__main__":
# Allow running directly: `python tests/test_progress_line.py`.
test_plain_progress_line_is_recognised()
Expand All @@ -60,4 +74,6 @@ def test_plain_log_line_is_passed_through():
test_non_numeric_progress_is_not_recognised()
test_empty_input_is_not_recognised()
test_plain_log_line_is_passed_through()
test_blank_console_line_is_suppressed()
test_non_blank_console_line_is_not_suppressed()
print("[OK] all parse_progress_line tests passed")
13 changes: 12 additions & 1 deletion utils/progress_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
_PROG_LINE_RE = re.compile(r"^\s*PROG:(\d+)\s*$")


def parse_progress_line(text: str) -> Optional[int]:
def parse_progress_line(text: Optional[str]) -> Optional[int]:
"""Return the integer percentage if ``text`` is a progress directive.

Returns ``None`` for any line that is not a standalone ``PROG:<N>``
Expand All @@ -40,3 +40,14 @@ def parse_progress_line(text: str) -> Optional[int]:
return int(match.group(1))
except (TypeError, ValueError):
return None


def is_blank_console_line(text: Optional[str]) -> bool:
"""Return ``True`` for output chunks that should not reach the log.

Progress-producing tools such as ``tqdm`` often emit standalone
carriage returns or empty newline chunks while redrawing a progress
line. Those chunks create visual blank rows in the GUI console, so the
log textbox should ignore them entirely.
"""
return text is None or text.strip() == ""