From 26e802d88b367e5bcc9f72ab6d40b4f107dd9ca4 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 4 Nov 2024 00:32:32 +0100 Subject: [PATCH] Add clickable links to file names in the printed report (#100) Co-authored-by: I-Al-Istannen --- CHANGELOG.md | 1 + PFERD/crawl/crawler.py | 4 ++++ PFERD/pferd.py | 14 ++++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3926f7a..c6c9cb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ ambiguous situations. ### Added - Support for MOB videos in page descriptions +- Clickable links in the report to directly open new/modified/not-deleted files ### Changed - Remove videos from description pages diff --git a/PFERD/crawl/crawler.py b/PFERD/crawl/crawler.py index dd500e6..fda1307 100644 --- a/PFERD/crawl/crawler.py +++ b/PFERD/crawl/crawler.py @@ -258,6 +258,10 @@ class Crawler(ABC): def prev_report(self) -> Optional[Report]: return self._output_dir.prev_report + @property + def output_dir(self) -> OutputDirectory: + return self._output_dir + @staticmethod async def gather(awaitables: Sequence[Awaitable[Any]]) -> List[Any]: """ diff --git a/PFERD/pferd.py b/PFERD/pferd.py index b30a04a..850e68e 100644 --- a/PFERD/pferd.py +++ b/PFERD/pferd.py @@ -1,5 +1,6 @@ -from pathlib import Path +from pathlib import Path, PurePath from typing import Dict, List, Optional +from urllib.parse import quote from rich.markup import escape @@ -168,19 +169,24 @@ class Pferd: log.report("") log.report(f"[bold bright_cyan]Report[/] for {escape(name)}") + def fmt_path_link(relative_path: PurePath) -> str: + # We need to URL-encode the path because it might contain spaces or special characters + link = f"file://{quote(str(crawler.output_dir.resolve(relative_path).absolute()))}" + return f"[link={link}]{fmt_path(relative_path)}[/link]" + something_changed = False for path in sorted(crawler.report.added_files): something_changed = True - log.report(f" [bold bright_green]Added[/] {fmt_path(path)}") + log.report(f" [bold bright_green]Added[/] {fmt_path_link(path)}") for path in sorted(crawler.report.changed_files): something_changed = True - log.report(f" [bold bright_yellow]Changed[/] {fmt_path(path)}") + log.report(f" [bold bright_yellow]Changed[/] {fmt_path_link(path)}") for path in sorted(crawler.report.deleted_files): something_changed = True log.report(f" [bold bright_magenta]Deleted[/] {fmt_path(path)}") for path in sorted(crawler.report.not_deleted_files): something_changed = True - log.report_not_deleted(f" [bold bright_magenta]Not deleted[/] {fmt_path(path)}") + log.report_not_deleted(f" [bold bright_magenta]Not deleted[/] {fmt_path_link(path)}") for warning in crawler.report.encountered_warnings: something_changed = True