Files
antidrift/antidrift/config.py
2022-06-25 19:24:06 -04:00

33 lines
754 B
Python

import os
import yaml
from pathlib import Path
from typing import List
from pydantic import BaseModel
class Block(BaseModel):
name: str
keywords: List[str]
class Config(BaseModel):
blackblocks: List[Block]
whiteblocks: List[Block]
log_file: Path = Path()
config_file: Path = Path()
check_delay: int = 1000
minimize_delay: int = 5
blackblocks_only: bool = True
class Config:
extra = 'forbid'
@classmethod
def load(cls, config_file: str) -> Config:
config_file = os.path.expanduser(config_file)
with open(config_file, "r") as f:
config_dict = yaml.safe_load(f)
config = cls(**config_dict)
config.config_file = Path(config_file)
return config