34 lines
814 B
Python
34 lines
814 B
Python
import json
|
|
import os
|
|
from typing import List
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class Block(BaseModel):
|
|
name: str = ''
|
|
prefix: str = ''
|
|
postfix: str = ''
|
|
items: List[str]
|
|
|
|
|
|
class Config(BaseModel):
|
|
directory: str
|
|
blocks: List[Block]
|
|
start_as_user: bool = True
|
|
sleep_time: int = 1
|
|
aw_focus_cmd: str = "aw-focus"
|
|
window_names: str = "window_names.txt"
|
|
enforce_aw_commit: bool = True
|
|
|
|
class Config:
|
|
extra = 'forbid'
|
|
|
|
@classmethod
|
|
def load_config(cls, config_file: str) -> Config:
|
|
config_file = os.path.expanduser(config_file)
|
|
with open(config_file, 'r', encoding='utf8') as f:
|
|
config_dict = json.load(f)
|
|
config = cls(**config_dict)
|
|
config.directory = os.path.expanduser(config.directory)
|
|
return config
|