From 5e5bd1dffe192387b8bd39c1c9531daa40ddcd91 Mon Sep 17 00:00:00 2001 From: Jan Willhaus Date: Wed, 1 Jan 2025 21:39:14 +0100 Subject: [PATCH] fix: Restore printing archived during progress (#227) --- config.yaml.example | 2 +- podcast_archiver/enums.py | 11 +++++------ podcast_archiver/processor.py | 4 +++- podcast_archiver/utils/pretty_printing.py | 7 +++---- podcast_archiver/utils/progress.py | 9 ++++----- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/config.yaml.example b/config.yaml.example index db5e3c1..d9b6abc 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -1,5 +1,5 @@ ## Podcast-Archiver configuration -## Generated using podcast-archiver v2.0.0 +## Generated using podcast-archiver v2.0.1 # Field 'feeds': Feed URLs to archive. # diff --git a/podcast_archiver/enums.py b/podcast_archiver/enums.py index 66d2315..267cdc1 100644 --- a/podcast_archiver/enums.py +++ b/podcast_archiver/enums.py @@ -35,7 +35,7 @@ def successful(cls) -> set[QueueCompletionType]: } def __rich__(self) -> RenderableType: - return Text(str(self), style=self.style, end="") + return Text(self.value, style=self.style, end="") class DownloadResult(StrEnum): @@ -60,12 +60,11 @@ def successful(cls) -> set[DownloadResult]: cls.COMPLETED_SUCCESSFULLY, } - @classmethod - def max_length(cls) -> int: - return max(len(v) for v in cls) - def render_padded(self, padding: str = " ") -> RenderableType: - return Text(f"{self:{self.max_length()}s}{padding}", style=self.style, end="") + return Text(f"{self.value:{RESULT_MAX_LEN}s}{padding}", style=self.style, end="") def __rich__(self) -> RenderableType: return self.render_padded() + + +RESULT_MAX_LEN = max(len(result.value) for result in DownloadResult) diff --git a/podcast_archiver/processor.py b/podcast_archiver/processor.py index f804136..ec99ad2 100644 --- a/podcast_archiver/processor.py +++ b/podcast_archiver/processor.py @@ -4,6 +4,8 @@ from threading import Event from typing import TYPE_CHECKING +from rich.console import Group, NewLine + from podcast_archiver import constants from podcast_archiver.config import Settings from podcast_archiver.database import get_database @@ -155,7 +157,7 @@ def _handle_results(self, episode_results: EpisodeResultsList) -> tuple[int, int else: failures += 1 - rprint(episode_result, new_line_start=False) + rprint(Group(episode_result, NewLine()), new_line_start=False) return success, failures def shutdown(self) -> None: diff --git a/podcast_archiver/utils/pretty_printing.py b/podcast_archiver/utils/pretty_printing.py index 2573af6..062ef66 100644 --- a/podcast_archiver/utils/pretty_printing.py +++ b/podcast_archiver/utils/pretty_printing.py @@ -7,7 +7,7 @@ from rich.console import Group, NewLine, group from rich.text import Text -from podcast_archiver.enums import DownloadResult +from podcast_archiver.enums import RESULT_MAX_LEN, DownloadResult from podcast_archiver.logging import rprint if TYPE_CHECKING: @@ -16,7 +16,6 @@ from podcast_archiver.models.episode import BaseEpisode -_PREFIX_LEN = DownloadResult.max_length() NEWLINE = NewLine() @@ -49,12 +48,12 @@ def render(self) -> Iterator[RenderableType]: yield NEWLINE if self.length > 2: - yield text(" " * _PREFIX_LEN + " │ ") + yield text(" " * RESULT_MAX_LEN + " │ ") yield text(" ︙", style="dim") yield NEWLINE if self.length > 1 and self.last: - yield text(" " * _PREFIX_LEN + " ╰╴") + yield text(" " * RESULT_MAX_LEN + " ╰╴") yield self.last yield NEWLINE yield NEWLINE diff --git a/podcast_archiver/utils/progress.py b/podcast_archiver/utils/progress.py index 9c2fec0..8cb9609 100644 --- a/podcast_archiver/utils/progress.py +++ b/podcast_archiver/utils/progress.py @@ -8,7 +8,7 @@ from rich.table import Column from podcast_archiver.console import console -from podcast_archiver.enums import DownloadResult +from podcast_archiver.enums import RESULT_MAX_LEN from podcast_archiver.logging import REDIRECT_VIA_LOGGING if TYPE_CHECKING: @@ -24,7 +24,6 @@ highlight=False, ) -_TIME_REMAINING_WIDTH = DownloadResult.max_length() PROGRESS_COLUMNS: list[rp.ProgressColumn] = [ rp.SpinnerColumn( @@ -33,9 +32,9 @@ rp.TimeRemainingColumn( compact=True, table_column=_Column( - width=_TIME_REMAINING_WIDTH, - min_width=_TIME_REMAINING_WIDTH, - max_width=_TIME_REMAINING_WIDTH, + width=RESULT_MAX_LEN, + min_width=RESULT_MAX_LEN, + max_width=RESULT_MAX_LEN, justify="center", ), ),