import os from typing import Callable from settings import Settings from pathlib import Path from os.path import join, isfile from configparser import ConfigParser class SettingsStore(): def __init__(self): pass @staticmethod def _config_file() -> str: return join(Path.home(), ".ravenlog", "settings.ini") @staticmethod def load() -> Settings: config_file = SettingsStore._config_file() config = ConfigParser() # apply default settings config.add_section('general') config.set('general', 'font_size', '12') config.read(config_file) return Settings(config) @staticmethod def save(settings: Settings): config_file = SettingsStore._config_file() dir = os.path.dirname(config_file) os.makedirs(dir, exist_ok=True) with open(config_file, 'w+') as fp: settings.config.write(fp)