import json from collections import UserDict import os import sys from . import data class SettingsLoader(UserDict): def __init__(self: object, files: list) -> None: self.data = {} self.files = files self.reload() def load_settings_file(self: object, file: str) -> None: ext = os.path.splitext(file)[1] with data.data_open('conf', file) as fd: if ext == '.json': self.data.update(json.load(fd)) else: raise ValueError("Cannot open this type of settings file") def reload(self: object) -> None: self.data = {} for f in self.files: self.load_settings_file(f) class SettingsReadOnly(SettingsLoader): pass class SettingsMutable(SettingsLoader): pass class SettingsWritable(SettingsMutable): pass init = SettingsWritable(['init.json'])