From d147958c7b08a0d74b46f523f5744327e61a85e6 Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Sat, 17 Feb 2024 01:04:46 +0100 Subject: [PATCH] implemented base interface for profiles --- configparser_toml/__init__.py | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/configparser_toml/__init__.py b/configparser_toml/__init__.py index e69de29..a0ba473 100644 --- a/configparser_toml/__init__.py +++ b/configparser_toml/__init__.py @@ -0,0 +1,43 @@ +from pathlib import Path + +import toml +import platformdirs + +from . shared import ENCODING + + +""" +I need a config directory, where I can store all config files. + +""" + + +CONFIG_DIR = Path.home() / ".config" / "configparser_toml" + + +class Config: + def __init__(self, appname: str, profile: str = None, config_dir: str = None): + self._config: dict = {} + + self.appname: str = appname + self.config_dir: Path = Path(config_dir or platformdirs.user_config_path(appname=appname)) + + self.config_file: Path = self.load_profile(profile) + + + def load_profile(self, profile: str = None) -> Path: + profile = profile if profile is not None else self.appname + + self.config_dir.mkdir(parents=True, exist_ok=True) + + self.config_file = self.config_dir / f"{profile}.toml" + return self.config_file + + + def read(self): + pass + + + def write(self): + with self.config_file.open("w", encoding=ENCODING) as f: + toml.dump(self._config, f)