bot-base/config/FileSystem.py

30 lines
751 B
Python
Raw Normal View History

2019-08-10 17:58:54 +02:00
import os
2019-08-14 15:42:52 +02:00
2019-08-10 17:58:54 +02:00
import yaml
2019-08-10 20:29:04 +02:00
from config.Base import Config
2019-08-10 17:58:54 +02:00
class FSConfig(Config):
2019-08-14 15:42:52 +02:00
path: str
2019-08-10 17:58:54 +02:00
def __init__(self, path="config.json", *args, **kwargs):
super().__init__(*args, **kwargs)
self.path = path
os.makedirs(os.path.dirname(path), exist_ok=True)
open(path, "a").close()
2019-08-14 15:42:52 +02:00
def _load(self):
with open(self.path, "r") as file:
content = file.read()
2019-08-10 17:58:54 +02:00
self.config = yaml.load(content, Loader=yaml.BaseLoader)
2019-08-14 15:42:52 +02:00
if self.config is None:
self.parent.config[self.name] = {}
self.config = {}
2019-08-10 17:58:54 +02:00
2019-08-14 15:42:52 +02:00
def _save(self):
2019-08-10 17:58:54 +02:00
content = yaml.dump(self.config)
2019-08-14 15:42:52 +02:00
print(self.config)
with open(self.path, "w") as file:
file.write(content)