From 577b2e26e7d83635d228fd3b85fe3feeef41a679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20S=C3=A9chet?= Date: Wed, 13 Apr 2022 11:30:45 +0200 Subject: [PATCH] cli: print a summary on quit --- frontools/cli.py | 40 +++++++++++++++++++++++++++++++++++----- frontools/config.py | 5 +++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/frontools/cli.py b/frontools/cli.py index 76c58d3..27b254c 100644 --- a/frontools/cli.py +++ b/frontools/cli.py @@ -1,6 +1,7 @@ """frontools main module""" from asyncio import run from functools import update_wrapper +from logging import INFO, basicConfig, getLogger from pathlib import Path from typing import Any, Optional @@ -9,8 +10,8 @@ from click import Path as PathArgument from click import argument, group, option, pass_context, pass_obj from frontools.config import Config -from frontools.sources import CachedSource from frontools.screenshot import screenshot_diff +from frontools.sources import CachedSource def _async_command(function: Any) -> Any: @@ -20,6 +21,9 @@ def _async_command(function: Any) -> Any: return update_wrapper(wrapper, function) +_LOGGER = getLogger(__file__) + + @group() @pass_context @option( @@ -79,7 +83,8 @@ async def main( exclude_tags: list[str], ) -> None: """Utilities for EO frontend development.""" - ctx.obj = await Config.load( + basicConfig(format="%(message)s", level=INFO) + config = await Config.load( config_file, update_index, source, @@ -90,6 +95,22 @@ async def main( exclude_tags, ) + def _on_close() -> None: + processed_urls: list[tuple[str, str]] = list(config.urls) + all_themes: set[str] = set(theme for theme, _ in ctx.obj.all_urls) + processed_themes: set[str] = set(theme for theme, _ in processed_urls) + ignored_themes: set[str] = all_themes - processed_themes + _LOGGER.info( + f"Processed {len(processed_urls)} urls belonging to {len(processed_themes)} out of {len(all_themes)} themes" + ) + if len(ignored_themes): + _LOGGER.info("Following themes were skipped :") + for theme in ignored_themes: + _LOGGER.info(theme) + + ctx.obj = config + ctx.call_on_close(_on_close) + @main.command(name="prune-caches") @argument("cache_names", nargs=-1) @@ -102,7 +123,14 @@ def prune_caches(cache_names: list[str]) -> None: @argument("source", type=str) @option("-o", "--output-directory", type=PathArgument(), default=None) @option("-w", "--screen-width", type=int, default=None) -@option("-c", "--continue", "continue_", type=bool, help="Don't reshot already existing screenshots", count=True) +@option( + "-c", + "--continue", + "continue_", + type=bool, + help="Don't reshot already existing screenshots", + count=True, +) @_async_command @pass_obj async def screenshot_diff_cli( @@ -110,10 +138,12 @@ async def screenshot_diff_cli( source: str, output_directory: Optional[str], screen_width: Optional[int], - continue_: bool + continue_: bool, ) -> None: """Generate screenshot diffs""" - await screenshot_diff(config, source, output_directory, screen_width=screen_width, continue_=continue_) + await screenshot_diff( + config, source, output_directory, screen_width=screen_width, continue_=continue_ + ) if __name__ == "__main__": diff --git a/frontools/config.py b/frontools/config.py index db26612..d8d3712 100644 --- a/frontools/config.py +++ b/frontools/config.py @@ -87,6 +87,11 @@ class Config: if self._filter(url, tags): yield theme, url + @property + def all_urls(self) -> Iterable[tuple[str, str]]: + for theme, url, tags in self._theme_index.urls: + yield theme, url + def add_local_themes_root(self, *directories: Union[Path, str]) -> None: """Add an url for a theme""" self._theme_index.add_local_themes_root(*[Path(it) for it in directories])