From d2fdab9ab7af3513ac67cd0503d167c5a8250ff3 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Fri, 20 Oct 2023 09:33:58 -0700 Subject: [PATCH] more --- src/ytdl_sub/cli/entrypoint.py | 14 +++++------ src/ytdl_sub/cli/output_summary.py | 40 +++++++++++++++++++++++++++++- tests/unit/cli/test_entrypoint.py | 10 ++++---- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/ytdl_sub/cli/entrypoint.py b/src/ytdl_sub/cli/entrypoint.py index d91d184d..8c6b3aab 100644 --- a/src/ytdl_sub/cli/entrypoint.py +++ b/src/ytdl_sub/cli/entrypoint.py @@ -97,14 +97,14 @@ def _download_subscriptions_from_yaml_files( subscriptions += Subscription.from_file_path(config=config, subscription_path=path) for subscription in subscriptions: - logger.info( - "Beginning subscription %s for %s", - ("dry run" if dry_run else "download"), - subscription.name, - ) - logger.debug("Subscription full yaml:\n%s", subscription.as_yaml()) - with subscription.exception_handling(): + logger.info( + "Beginning subscription %s for %s", + ("dry run" if dry_run else "download"), + subscription.name, + ) + logger.debug("Subscription full yaml:\n%s", subscription.as_yaml()) + if update_with_info_json: subscription.update_with_info_json(dry_run=dry_run) else: diff --git a/src/ytdl_sub/cli/output_summary.py b/src/ytdl_sub/cli/output_summary.py index d08ff1bf..e50701ca 100644 --- a/src/ytdl_sub/cli/output_summary.py +++ b/src/ytdl_sub/cli/output_summary.py @@ -35,7 +35,7 @@ def _color_int(value: int) -> str: return _no_color(str_int) -def output_summary(subscriptions: List[Subscription]) -> str: +def output_summary(subscriptions: List[Subscription]) -> None: """ Parameters ---------- @@ -48,6 +48,14 @@ def output_summary(subscriptions: List[Subscription]) -> str: """ summary: List[str] = [] + # Initialize totals to 0 + total_subs: int = 0 + total_added: int = 0 + total_modified: int = 0 + total_removed: int = 0 + total_entries: int = 0 + total_errors: int = 0 + # Initialize widths to 0 width_sub_name: int = 0 width_num_entries_added: int = 0 @@ -90,5 +98,35 @@ def output_summary(subscriptions: List[Subscription]) -> str: f"{status}" ) + # Add total + total_subs += 1 + total_added += subscription.num_entries_added + total_modified += subscription.num_entries_modified + total_removed -= subscription.num_entries_removed + total_entries += subscription.num_entries + total_errors += int(subscription.exception is not None) + + total_subs_str = f"Total: {total_subs} Subscriptions" + total_errors_str = ( + _green("All Successful") + if total_errors == 0 + else _red(f"{total_errors} Error{'s' if total_errors > 1 else ''}") + ) + + summary.append("") # new line + summary.append( + f"{total_subs_str:<{width_sub_name}} " + f"{_color_int(total_added):>{width_num_entries_added}} " + f"{_color_int(total_modified):>{width_num_entries_modified}} " + f"{_color_int(total_removed):>{width_num_entries_removed}} " + f"{str(total_entries):>{width_num_entries}} " + f"{total_errors_str}" + ) + + if total_errors > 0: + summary.append("") + summary.append(f"See `{Logger.debug_log_filename()}` for details on errors.") + summary.append("Consider making a GitHub issue including the uploaded log file.") + # Hack to always show download summary, even if logs are set to quiet logger.warning("Download Summary:\n%s", "\n".join(summary)) diff --git a/tests/unit/cli/test_entrypoint.py b/tests/unit/cli/test_entrypoint.py index 08ae5b87..707eea10 100644 --- a/tests/unit/cli/test_entrypoint.py +++ b/tests/unit/cli/test_entrypoint.py @@ -260,11 +260,11 @@ def test_transaction_log_to_logger( def test_output_summary(): - subscription_values: List[Tuple[str, int, int, int, int, bool]] = [ - ("long_name_but_lil_values", 0, 0, 0, 6, False), - ("john_smith", 1, 0, 0, 52, False), - ("david_gore", 0, 0, 0, 4, False), - ("christopher_snoop", 50, 0, 3, 518, False), + subscription_values: List[Tuple[str, int, int, int, int, Optional[bool]]] = [ + ("long_name_but_lil_values", 0, 0, 0, 6, None), + ("john_smith", 1, 0, 0, 52, None), + ("david_gore", 0, 0, 0, 4, None), + ("christopher_snoop", 50, 0, 3, 518, None), ("beyond funk", 0, 0, 0, 176, True), ]