mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Align paths in status messages and progress bars
Also print "Ignored" when paths are ignored due to transforms
This commit is contained in:
parent
17879a7f69
commit
64a2960751
@ -5,8 +5,6 @@ from datetime import datetime
|
|||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
from typing import Any, Awaitable, Callable, Dict, List, Optional, Sequence, Set, Tuple, TypeVar
|
from typing import Any, Awaitable, Callable, Dict, List, Optional, Sequence, Set, Tuple, TypeVar
|
||||||
|
|
||||||
from rich.markup import escape
|
|
||||||
|
|
||||||
from ..auth import Authenticator
|
from ..auth import Authenticator
|
||||||
from ..config import Config, Section
|
from ..config import Config, Section
|
||||||
from ..deduplicator import Deduplicator
|
from ..deduplicator import Deduplicator
|
||||||
@ -104,12 +102,9 @@ class CrawlToken(ReusableAsyncContextManager[ProgressBar]):
|
|||||||
return self._path
|
return self._path
|
||||||
|
|
||||||
async def _on_aenter(self) -> ProgressBar:
|
async def _on_aenter(self) -> ProgressBar:
|
||||||
bar_desc = f"[bold bright_cyan]Crawling[/] {escape(fmt_path(self._path))}"
|
self._stack.callback(lambda: log.status("[bold cyan]", "Crawled", fmt_path(self._path)))
|
||||||
after_desc = f"[bold cyan]Crawled[/] {escape(fmt_path(self._path))}"
|
|
||||||
|
|
||||||
self._stack.callback(lambda: log.status(after_desc))
|
|
||||||
await self._stack.enter_async_context(self._limiter.limit_crawl())
|
await self._stack.enter_async_context(self._limiter.limit_crawl())
|
||||||
bar = self._stack.enter_context(log.crawl_bar(bar_desc))
|
bar = self._stack.enter_context(log.crawl_bar("[bold bright_cyan]", "Crawling", fmt_path(self._path)))
|
||||||
|
|
||||||
return bar
|
return bar
|
||||||
|
|
||||||
@ -127,12 +122,11 @@ class DownloadToken(ReusableAsyncContextManager[Tuple[ProgressBar, FileSink]]):
|
|||||||
return self._path
|
return self._path
|
||||||
|
|
||||||
async def _on_aenter(self) -> Tuple[ProgressBar, FileSink]:
|
async def _on_aenter(self) -> Tuple[ProgressBar, FileSink]:
|
||||||
bar_desc = f"[bold bright_cyan]Downloading[/] {escape(fmt_path(self._path))}"
|
|
||||||
# The "Downloaded ..." message is printed in the output dir, not here
|
|
||||||
|
|
||||||
await self._stack.enter_async_context(self._limiter.limit_download())
|
await self._stack.enter_async_context(self._limiter.limit_download())
|
||||||
sink = await self._stack.enter_async_context(self._fs_token)
|
sink = await self._stack.enter_async_context(self._fs_token)
|
||||||
bar = self._stack.enter_context(log.download_bar(bar_desc))
|
# The "Downloaded ..." message is printed in the output dir, not here
|
||||||
|
bar = self._stack.enter_context(log.download_bar("[bold bright_cyan]", "Downloading",
|
||||||
|
fmt_path(self._path)))
|
||||||
|
|
||||||
return bar, sink
|
return bar, sink
|
||||||
|
|
||||||
@ -273,6 +267,7 @@ class Crawler(ABC):
|
|||||||
|
|
||||||
if self._transformer.transform(path) is None:
|
if self._transformer.transform(path) is None:
|
||||||
log.explain("Answer: No")
|
log.explain("Answer: No")
|
||||||
|
log.status("[bold bright_black]", "Ignored", fmt_path(path))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
log.explain("Answer: Yes")
|
log.explain("Answer: Yes")
|
||||||
@ -291,6 +286,7 @@ class Crawler(ABC):
|
|||||||
transformed_path = self._transformer.transform(path)
|
transformed_path = self._transformer.transform(path)
|
||||||
if transformed_path is None:
|
if transformed_path is None:
|
||||||
log.explain("Answer: No")
|
log.explain("Answer: No")
|
||||||
|
log.status("[bold bright_black]", "Ignored", fmt_path(path))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
fs_token = await self._output_dir.download(path, transformed_path, mtime, redownload, on_conflict)
|
fs_token = await self._output_dir.download(path, transformed_path, mtime, redownload, on_conflict)
|
||||||
|
@ -28,6 +28,8 @@ class ProgressBar:
|
|||||||
|
|
||||||
|
|
||||||
class Log:
|
class Log:
|
||||||
|
STATUS_WIDTH = 11
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.console = Console(highlight=False)
|
self.console = Console(highlight=False)
|
||||||
|
|
||||||
@ -195,13 +197,15 @@ directly or as a GitHub issue: https://github.com/Garmelon/PFERD/issues/new
|
|||||||
if self.output_explain:
|
if self.output_explain:
|
||||||
self.print(f" {escape(text)}")
|
self.print(f" {escape(text)}")
|
||||||
|
|
||||||
def status(self, text: str) -> None:
|
def status(self, style: str, action: str, text: str) -> None:
|
||||||
"""
|
"""
|
||||||
Print a status update while crawling. Allows markup.
|
Print a status update while crawling. Allows markup in the "style"
|
||||||
|
argument which will be applied to the "action" string.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.output_status:
|
if self.output_status:
|
||||||
self.print(text)
|
action = escape(f"{action:<{self.STATUS_WIDTH}}")
|
||||||
|
self.print(f"{style}{action}[/] {escape(text)}")
|
||||||
|
|
||||||
def report(self, text: str) -> None:
|
def report(self, text: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -233,16 +237,34 @@ directly or as a GitHub issue: https://github.com/Garmelon/PFERD/issues/new
|
|||||||
|
|
||||||
def crawl_bar(
|
def crawl_bar(
|
||||||
self,
|
self,
|
||||||
description: str,
|
style: str,
|
||||||
|
action: str,
|
||||||
|
text: str,
|
||||||
total: Optional[float] = None,
|
total: Optional[float] = None,
|
||||||
) -> ContextManager[ProgressBar]:
|
) -> ContextManager[ProgressBar]:
|
||||||
|
"""
|
||||||
|
Allows markup in the "style" argument which will be applied to the
|
||||||
|
"action" string.
|
||||||
|
"""
|
||||||
|
|
||||||
|
action = escape(f"{action:<{self.STATUS_WIDTH}}")
|
||||||
|
description = f"{style}{action}[/] {text}"
|
||||||
return self._bar(self._crawl_progress, description, total)
|
return self._bar(self._crawl_progress, description, total)
|
||||||
|
|
||||||
def download_bar(
|
def download_bar(
|
||||||
self,
|
self,
|
||||||
description: str,
|
style: str,
|
||||||
|
action: str,
|
||||||
|
text: str,
|
||||||
total: Optional[float] = None,
|
total: Optional[float] = None,
|
||||||
) -> ContextManager[ProgressBar]:
|
) -> ContextManager[ProgressBar]:
|
||||||
|
"""
|
||||||
|
Allows markup in the "style" argument which will be applied to the
|
||||||
|
"action" string.
|
||||||
|
"""
|
||||||
|
|
||||||
|
action = escape(f"{action:<{self.STATUS_WIDTH}}")
|
||||||
|
description = f"{style}{action}[/] {text}"
|
||||||
return self._bar(self._download_progress, description, total)
|
return self._bar(self._download_progress, description, total)
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@ from enum import Enum
|
|||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
from typing import BinaryIO, Iterator, Optional, Tuple
|
from typing import BinaryIO, Iterator, Optional, Tuple
|
||||||
|
|
||||||
from rich.markup import escape
|
|
||||||
|
|
||||||
from .logging import log
|
from .logging import log
|
||||||
from .report import Report, ReportLoadError
|
from .report import Report, ReportLoadError
|
||||||
from .utils import ReusableAsyncContextManager, fmt_path, fmt_real_path, prompt_yes_no
|
from .utils import ReusableAsyncContextManager, fmt_path, fmt_real_path, prompt_yes_no
|
||||||
@ -425,7 +423,7 @@ class OutputDirectory:
|
|||||||
|
|
||||||
async def _after_download(self, info: DownloadInfo) -> None:
|
async def _after_download(self, info: DownloadInfo) -> None:
|
||||||
with self._ensure_deleted(info.tmp_path):
|
with self._ensure_deleted(info.tmp_path):
|
||||||
log.status(f"[bold cyan]Downloaded[/] {fmt_path(info.remote_path)}")
|
log.status("[bold cyan]", "Downloaded", fmt_path(info.remote_path))
|
||||||
log.explain_topic(f"Processing downloaded file for {fmt_path(info.path)}")
|
log.explain_topic(f"Processing downloaded file for {fmt_path(info.path)}")
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
@ -456,10 +454,10 @@ class OutputDirectory:
|
|||||||
self._update_metadata(info)
|
self._update_metadata(info)
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
log.status(f"[bold bright_yellow]Changed[/] {escape(fmt_path(info.path))}")
|
log.status("[bold bright_yellow]", "Changed", fmt_path(info.path))
|
||||||
self._report.change_file(info.path)
|
self._report.change_file(info.path)
|
||||||
else:
|
else:
|
||||||
log.status(f"[bold bright_green]Added[/] {escape(fmt_path(info.path))}")
|
log.status("[bold bright_green]", "Added", fmt_path(info.path))
|
||||||
self._report.add_file(info.path)
|
self._report.add_file(info.path)
|
||||||
|
|
||||||
async def cleanup(self) -> None:
|
async def cleanup(self) -> None:
|
||||||
@ -489,12 +487,12 @@ class OutputDirectory:
|
|||||||
if await self._conflict_delete_lf(self._on_conflict, pure):
|
if await self._conflict_delete_lf(self._on_conflict, pure):
|
||||||
try:
|
try:
|
||||||
path.unlink()
|
path.unlink()
|
||||||
log.status(f"[bold bright_magenta]Deleted[/] {escape(fmt_path(pure))}")
|
log.status("[bold bright_magenta]", "Deleted", fmt_path(pure))
|
||||||
self._report.delete_file(pure)
|
self._report.delete_file(pure)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
log.status(f"[bold bright_magenta]Not deleted[/] {escape(fmt_path(pure))}")
|
log.status("[bold bright_magenta]", "Not deleted", fmt_path(pure))
|
||||||
self._report.not_delete_file(pure)
|
self._report.not_delete_file(pure)
|
||||||
|
|
||||||
def load_prev_report(self) -> None:
|
def load_prev_report(self) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user