Files
krowlog/settingsstore.py
Andreas Huber 9fb8a45ef7 save highlighters
remove user config (not needed)
2021-10-31 18:05:10 +01:00

45 lines
1.2 KiB
Python

import os
import sys
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 _session_file() -> str:
if sys.platform == 'win32' or sys.platform == 'cygwin':
return join(Path.home(), "AppData", "Local", "ravenlog", "session.ini")
else:
return join(Path.home(), ".local", "share", "ravenlog", "session.ini")
@staticmethod
def load() -> Settings:
session = SettingsStore._load_session()
return Settings(session)
@staticmethod
def _load_session() -> ConfigParser:
session_file = SettingsStore._session_file()
session = ConfigParser()
# apply default settings
session.add_section('general')
session.set('general', 'font_size', '12')
session.read(session_file)
return session
@staticmethod
def save(settings: Settings):
session_file = SettingsStore._session_file()
dir = os.path.dirname(session_file)
os.makedirs(dir, exist_ok=True)
with open(session_file, 'w+') as fp:
settings.session.write(fp)