common: add warning when local and configured url mismatch

This commit is contained in:
Corentin Sechet 2022-04-12 13:44:42 +02:00
parent ae22aa4c41
commit 4bb5703a81
2 changed files with 45 additions and 0 deletions

View File

@ -87,6 +87,10 @@ class Config:
if self._filter(url, tags):
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])
def add_urls(self, *urls: UrlEntry) -> None:
"""Add an url for a theme"""
self._theme_index.add_urls(*urls)

View File

@ -35,6 +35,7 @@ class ThemeIndex:
def __init__(self) -> None:
self._themes: ThemeIndexData = {}
self._inputs = _Inputs()
self._local_theme_roots: list[Path] = []
@property
def urls(self) -> Iterable[tuple[str, str, set[str]]]:
@ -43,6 +44,10 @@ class ThemeIndex:
for url, tags in theme.items():
yield theme_name, url, set(tags)
def add_local_themes_root(self, *directories: Path) -> None:
"""Add an url for a theme"""
self._local_theme_roots.extend(directories)
def add_urls(self, *urls: UrlEntry) -> None:
"""Add an url for a theme"""
self._inputs.urls.extend(urls)
@ -66,6 +71,31 @@ class ThemeIndex:
dump(self._themes, index_cache_handle)
self._load_yaml_files()
self._check_local_themes()
def _check_local_themes(self) -> None:
local_themes: set[str] = set()
for theme_root in self._local_theme_roots:
local_themes.update(set(_get_local_themes(theme_root)))
config_themes = set(self._themes)
unknown_themes = config_themes - local_themes
unconfigured_themes = local_themes - config_themes
if unknown_themes:
_LOGGER.warn(
"* Following themes are present in index but have no local source :"
)
for theme_name in sorted(unknown_themes):
_LOGGER.warn(theme_name)
if unconfigured_themes:
_LOGGER.warn(
"* Following themes are present in local sources but have no url configured in index :"
)
for theme_name in sorted(unconfigured_themes):
_LOGGER.warn(theme_name)
async def _load_urls_without_theme(self) -> None:
async def _load(url: str, tags: list[str]) -> None:
@ -221,3 +251,14 @@ async def _get_node_urls(
if service_id == "authentic":
base_url = base_url + "login/"
yield (base_url, [service_id], theme)
def _get_local_themes(root: Path) -> Iterable[str]:
static = root / "static"
for theme_dir in static.iterdir():
theme_scss = theme_dir / "style.scss"
if not theme_scss.is_file():
continue
yield theme_dir.name