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

1#! /usr/bin/env python3

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

3

4 import json

5 from typing import Dict

6 from pathlib import Path

7

8 class 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)