common: allow to ignore themes

This commit is contained in:
Corentin Sechet 2022-04-13 00:52:26 +02:00
parent 0cc1273044
commit 87e25c1697
2 changed files with 13 additions and 4 deletions

View File

@ -99,6 +99,10 @@ class Config:
"""Add an url for a theme"""
self._theme_index.add_nodes(*nodes)
def ignore_themes(self, *themes: str) -> None:
"""Don't add given theme to the index, and don't check for them in local sources."""
self._theme_index.ignore_themes(*themes)
def add_yaml(self, yaml_path: Union[str, Path]) -> None:
"""Load a yaml file containing dictionnary of urls to add as themes."""
self._theme_index.add_yaml(Path(yaml_path))

View File

@ -36,6 +36,7 @@ class ThemeIndex:
self._themes: ThemeIndexData = {}
self._inputs = _Inputs()
self._local_theme_roots: list[Path] = []
self._ignored_themes: set[str] = set()
@property
def urls(self) -> Iterable[tuple[str, str, set[str]]]:
@ -56,6 +57,10 @@ class ThemeIndex:
"""Add an url for a theme"""
self._inputs.nodes.extend(nodes)
def ignore_themes(self, *themes: str) -> None:
"""Add an url for a theme"""
self._ignored_themes.update(set(themes))
def add_yaml(self, yaml_path: Path) -> None:
"""Load a yaml file containing dictionnary of urls to add as themes."""
self._inputs.yaml_files.append(yaml_path)
@ -79,6 +84,7 @@ class ThemeIndex:
local_themes.update(set(_get_local_themes(theme_root)))
config_themes = set(self._themes)
local_themes = local_themes - self._ignored_themes
unknown_themes = config_themes - local_themes
unconfigured_themes = local_themes - config_themes
@ -143,8 +149,7 @@ class ThemeIndex:
def _register(self, url: str, new_tags: list[str], theme_name: str) -> None:
"""Add an url for a theme"""
if theme_name is None:
self._unknown_themes.append((url, new_tags))
if theme_name in self._ignored_themes:
return
theme = self._themes.get(theme_name, None)
@ -175,7 +180,7 @@ async def _get_theme(url: str) -> Optional[str]:
ssl_context.check_hostname = False
ssl_context.verify_mode = CERT_NONE
ssl_context.set_ciphers("DEFAULT@SECLEVEL=1")
async with session.get(url, ssl_context=ssl_context) as response:
async with session.get(url, ssl=ssl_context) as response:
page_content = await response.content.read()
page_html = BeautifulSoup(page_content, features="html5lib")
links = page_html.find_all("link")
@ -198,7 +203,7 @@ async def _get_theme(url: str) -> Optional[str]:
CAT_HOBO_JSON_SCRIPT = """
for hobo_json in $(find /var/lib/combo/ -name hobo.json); do
for hobo_json in $(find /var/lib/combo/tenants/ -name hobo.json); do
sudo cat $hobo_json
echo ","
done