44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
"""Global context object"""
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
from click import echo
|
|
|
|
from frontools.config import Config
|
|
|
|
|
|
class Context:
|
|
"""Configuration object"""
|
|
|
|
def __init__(self, config: Config) -> None:
|
|
"""Load config from the given path"""
|
|
|
|
self._config = config
|
|
self._errors: list[str] = []
|
|
|
|
@staticmethod
|
|
async def load(
|
|
config_path: Optional[Path],
|
|
default_source_name: Optional[str],
|
|
use_cache: bool,
|
|
include_urls: list[str],
|
|
exclude_urls: list[str],
|
|
) -> "Context":
|
|
config = await Config.load(
|
|
config_path, default_source_name, use_cache, include_urls, exclude_urls
|
|
)
|
|
return Context(config)
|
|
|
|
def add_error(self, message: str) -> None:
|
|
self._errors.append(message)
|
|
|
|
def print_error_summary(self) -> None:
|
|
echo("***** Error summary :")
|
|
for error in self._errors:
|
|
echo(error, err=True)
|
|
|
|
@property
|
|
def config(self) -> Config:
|
|
"""Get configuration object for this run"""
|
|
return self._config
|