Coverage for aipyapp/config/base.py: 0%

18 statements  

« prev     ^ index     » next       coverage.py v7.10.3, created at 2025-08-11 12:02 +0200

1#! /usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3 

4import json 

5from typing import Dict 

6from pathlib import Path 

7 

8class BaseConfig: 

9 FILE = None 

10 

11 def __init__(self, path: str): 

12 path = Path(path) 

13 path.mkdir(parents=True, exist_ok=True) 

14 self.config_file = path / self.FILE 

15 self.config = self.load_config() 

16 

17 def load_config(self) -> Dict: 

18 if self.config_file.exists(): 

19 with open(self.config_file, 'r', encoding='utf-8') as f: 

20 return json.load(f) 

21 return {} 

22 

23 def save_config(self, config: Dict): 

24 with open(self.config_file, 'w', encoding='utf-8') as f: 

25 json.dump(config, f, indent=2)