From 5125e02d3c7c262de7b9241f30b84118fbd8fd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20S=C3=A9chet?= Date: Tue, 12 Apr 2022 11:14:46 +0200 Subject: [PATCH] common: rename sites to theme --- frontools/__init__.py | 6 ++---- frontools/config.py | 38 +++++++++++++++++++------------------- frontools/screenshot.py | 10 +++++----- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/frontools/__init__.py b/frontools/__init__.py index f79fa14..7234359 100644 --- a/frontools/__init__.py +++ b/frontools/__init__.py @@ -1,7 +1,5 @@ """ Core module for Frontools""" -from .config import Config, SiteConfig -from .sources import get_page_stylesheets -from .utils import report_progress +from .config import Config -__all__ = ["Config", "SiteConfig", "report_progress", "get_page_stylesheets"] +__all__ = ["Config"] diff --git a/frontools/config.py b/frontools/config.py index b3a570a..ab5126a 100644 --- a/frontools/config.py +++ b/frontools/config.py @@ -28,8 +28,8 @@ class UrlConfig: self.tags: set[str] = set() -class SiteConfig: - """Configuration object for a particular website""" +class ThemeConfig: + """Configuration object for a particular webtheme""" def __init__(self) -> None: self.urls: dict[str, UrlConfig] = {} @@ -49,7 +49,7 @@ class Config: ): self._use_cache = use_cache self._sources: dict[str, Source] = {} - self._sites: dict[str, SiteConfig] = {} + self._themes: dict[str, ThemeConfig] = {} self._block_urls: list[Pattern[str]] = [] if default_source_name is None: @@ -123,41 +123,41 @@ class Config: @property def urls(self) -> Iterable[tuple[str, str]]: - """Return sites configured for this context""" - for site_name, site in self._sites.items(): - for url, config in site.urls.items(): + """Return themes configured for this context""" + for theme_name, theme in self._themes.items(): + for url, config in theme.urls.items(): if self._filter(url, config.tags): - yield site_name, url + yield theme_name, url - def add_site_url( + def add_theme_url( self, name: str, url: str, tags: Optional[Iterable[str]] = None ) -> None: - """Add an url for a site""" + """Add an url for a theme""" - site = self._sites.get(name, None) - if site is None: - site = SiteConfig() - self._sites[name] = site + theme = self._themes.get(name, None) + if theme is None: + theme = ThemeConfig() + self._themes[name] = theme if tags is None: new_tags = set() else: new_tags = set(tags) - url_config = site.urls.get(url, None) + url_config = theme.urls.get(url, None) if url_config is None: url_config = UrlConfig() - site.urls[url] = url_config + theme.urls[url] = url_config url_config.tags.update(new_tags) - def load_sites_from_yaml(self, yaml_path: str) -> None: - """Load a yaml file containing dictionnary of urls to add as sites.""" + def load_urls(self, yaml_path: str) -> None: + """Load a yaml file containing dictionnary of urls to add as themes.""" with open(yaml_path, "r", encoding="utf-8") as yaml_file: yaml_document = load_yaml(yaml_file, Loader) - for site_name, urls in yaml_document.items(): + for theme_name, urls in yaml_document.items(): for url, tags in urls.items(): - self.add_site_url(site_name, url, tags) + self.add_theme_url(theme_name, url, tags) def block_url_patterns(self, *patterns: str) -> None: """Will return 500 error for urls matching this pattern.""" diff --git a/frontools/screenshot.py b/frontools/screenshot.py index 2576e5b..19f3a9f 100644 --- a/frontools/screenshot.py +++ b/frontools/screenshot.py @@ -44,10 +44,10 @@ async def screenshot_diff( right_browser, url, output_path, - site_name, + theme_name, ), ) - for (site_name, url) in config.urls + for (theme_name, url) in config.urls ], nb_workers=3, ) @@ -58,7 +58,7 @@ async def _diff_url( right: Browser, url: str, output_path: Path, - site_name: str, + theme_name: str, ) -> None: left_bytes = await _screenshot_url(left, url) right_bytes = await _screenshot_url(right, url) @@ -80,10 +80,10 @@ async def _diff_url( if not output_path.is_dir(): output_path.mkdir() - with open(output_path / f"{site_name}_{url_slug}_left", "wb") as screenshot_file: + with open(output_path / f"{theme_name}_{url_slug}_left", "wb") as screenshot_file: screenshot_file.write(left_bytes) - with open(output_path / f"{site_name}_{url_slug}_right", "wb") as screenshot_file: + with open(output_path / f"{theme_name}_{url_slug}_right", "wb") as screenshot_file: screenshot_file.write(right_bytes)