antidrift/antidrift/config.py

36 lines
876 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]
kill: bool = False
class Config(BaseModel):
blackblocks: List[Block]
whiteblocks: List[Block]
active_blackblocks: List[Block] = []
active_whiteblocks: List[Block] = []
daemon_log_file: Path = Path()
client_log_file: Path = Path()
config_file: Path = Path()
polling_cycle_ms: int = 500
enforce_delay_ms: int = 5000
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