implemented base interface for profiles
This commit is contained in:
parent
59cb824b5c
commit
d147958c7b
@ -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)
|
Loading…
Reference in New Issue
Block a user