cli: print a summary on quit
This commit is contained in:
parent
424d520c2b
commit
577b2e26e7
|
@ -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__":
|
||||
|
|
|
@ -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])
|
||||
|
|
Loading…
Reference in New Issue