121 lines
3.0 KiB
Python
121 lines
3.0 KiB
Python
"""frontools main module"""
|
|
from asyncio import run
|
|
from functools import update_wrapper
|
|
from pathlib import Path
|
|
from typing import Any, Optional
|
|
|
|
from click import Context as ClickContext
|
|
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
|
|
|
|
|
|
def _async_command(function: Any) -> Any:
|
|
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
return run(function(*args, **kwargs))
|
|
|
|
return update_wrapper(wrapper, function)
|
|
|
|
|
|
@group()
|
|
@pass_context
|
|
@option(
|
|
"-c",
|
|
"--config-file",
|
|
type=PathArgument(exists=True, file_okay=True, dir_okay=False),
|
|
default=None,
|
|
metavar="FILE",
|
|
help="Configuration file to use",
|
|
)
|
|
@option(
|
|
"-s",
|
|
"source",
|
|
type=str,
|
|
required=True,
|
|
default="remote",
|
|
help="Source to use (configured in config file)",
|
|
)
|
|
@option("--no-cache", type=bool, help="Disable caching", count=True)
|
|
@option("-u", "--update-index", type=bool, help="Reload cached theme index", count=True)
|
|
@option(
|
|
"--include-urls",
|
|
type=str,
|
|
multiple=True,
|
|
help="Take into account only urls matching these patterns",
|
|
)
|
|
@option(
|
|
"--exclude-urls",
|
|
type=str,
|
|
multiple=True,
|
|
help="Ignore urls matching this pattern",
|
|
)
|
|
@option(
|
|
"-i",
|
|
"--include-tags",
|
|
type=str,
|
|
multiple=True,
|
|
help="Take into account only urls with those tags",
|
|
)
|
|
@option(
|
|
"-e",
|
|
"--exclude-tags",
|
|
type=str,
|
|
multiple=True,
|
|
help="Ignore urls matching with those tags",
|
|
)
|
|
@_async_command
|
|
async def main(
|
|
ctx: ClickContext,
|
|
config_file: Optional[Path],
|
|
source: str,
|
|
no_cache: bool,
|
|
update_index: bool,
|
|
include_urls: list[str],
|
|
exclude_urls: list[str],
|
|
include_tags: list[str],
|
|
exclude_tags: list[str],
|
|
) -> None:
|
|
"""Utilities for EO frontend development."""
|
|
ctx.obj = await Config.load(
|
|
config_file,
|
|
update_index,
|
|
source,
|
|
not no_cache,
|
|
include_urls,
|
|
exclude_urls,
|
|
include_tags,
|
|
exclude_tags,
|
|
)
|
|
|
|
|
|
@main.command(name="prune-caches")
|
|
@argument("cache_names", nargs=-1)
|
|
def prune_caches(cache_names: list[str]) -> None:
|
|
"""Prune frontools caches"""
|
|
CachedSource.prune(cache_names)
|
|
|
|
|
|
@main.command(name="screenshot-diff")
|
|
@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)
|
|
@_async_command
|
|
@pass_obj
|
|
async def screenshot_diff_cli(
|
|
config: Config,
|
|
source: str,
|
|
output_directory: Optional[str],
|
|
screen_width: Optional[int],
|
|
continue_: bool
|
|
) -> None:
|
|
"""Generate screenshot diffs"""
|
|
await screenshot_diff(config, source, output_directory, screen_width=screen_width, continue_=continue_)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() # pylint: disable=no-value-for-parameter
|