bot-base/config/FileSystem.py

28 lines
655 B
Python
Raw Normal View History

2019-08-10 17:58:54 +02:00
import os
2019-08-14 15:42:52 +02:00
import toml
2019-08-10 17:58:54 +02:00
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
def __init__(self, path="config.toml", *args, **kwargs):
2019-08-10 17:58:54 +02:00
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()
self.config = toml.loads(content)
2019-08-14 15:42:52 +02:00
if self.config is None:
self.config = {}
2019-08-10 17:58:54 +02:00
2019-08-14 15:42:52 +02:00
def _save(self):
content = toml.dumps(self.config)
2019-08-14 15:42:52 +02:00
with open(self.path, "w") as file:
file.write(content)