2022-09-29 13:45:06 +01:00
|
|
|
import logging
|
2022-04-11 18:35:28 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
2022-09-03 19:29:57 +01:00
|
|
|
try:
|
|
|
|
import tomllib
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
import tomli as tomllib
|
2022-06-16 23:53:28 +01:00
|
|
|
|
2023-06-26 13:53:38 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
2022-09-29 13:45:06 +01:00
|
|
|
|
2022-04-11 18:35:28 +01:00
|
|
|
configuration = {}
|
|
|
|
|
2023-06-26 13:53:38 +01:00
|
|
|
configpaths = [
|
|
|
|
Path.cwd() / "configs",
|
|
|
|
Path.home() / ".config" / "vm-compact" / "configs",
|
|
|
|
Path.home() / "Documents" / "Voicemeeter" / "configs",
|
|
|
|
]
|
|
|
|
for configpath in configpaths:
|
|
|
|
if configpath.is_dir():
|
|
|
|
filepaths = list(configpath.glob("*.toml"))
|
|
|
|
if any(f.stem in ("app", "vban") for f in filepaths):
|
|
|
|
configs = {}
|
|
|
|
for filepath in filepaths:
|
|
|
|
filename = filepath.with_suffix("").stem
|
|
|
|
if filename in ("app", "vban"):
|
|
|
|
try:
|
|
|
|
with open(filepath, "rb") as f:
|
|
|
|
configs[filename] = tomllib.load(f)
|
2023-06-26 16:08:58 +01:00
|
|
|
logger.info(f"configuration: {filename} loaded into memory")
|
2023-06-26 13:53:38 +01:00
|
|
|
except tomllib.TOMLDecodeError:
|
|
|
|
logger.error(f"Invalid TOML config: configs/{filename.stem}")
|
|
|
|
|
|
|
|
configuration |= configs
|
|
|
|
break
|
2022-05-10 20:34:29 +01:00
|
|
|
|
|
|
|
_defaults = {
|
2022-06-17 17:53:46 +01:00
|
|
|
"configs": {
|
|
|
|
"config": None,
|
2022-05-10 20:34:29 +01:00
|
|
|
},
|
|
|
|
"theme": {
|
|
|
|
"enabled": True,
|
|
|
|
"mode": "light",
|
|
|
|
},
|
|
|
|
"extends": {
|
|
|
|
"extended": True,
|
|
|
|
"extends_horizontal": True,
|
|
|
|
},
|
|
|
|
"channel": {
|
|
|
|
"width": 80,
|
|
|
|
"height": 130,
|
2023-06-29 17:15:03 +01:00
|
|
|
"xpadding": 3,
|
2022-05-10 20:34:29 +01:00
|
|
|
},
|
|
|
|
"mwscroll_step": {
|
|
|
|
"size": 3,
|
|
|
|
},
|
|
|
|
"submixes": {
|
|
|
|
"default": 0,
|
|
|
|
},
|
2023-06-29 17:15:03 +01:00
|
|
|
"navigation": {"show": True},
|
2022-05-10 20:34:29 +01:00
|
|
|
}
|
|
|
|
|
2023-06-29 19:13:06 +01:00
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
if "app" in configuration:
|
2023-06-29 19:13:06 +01:00
|
|
|
for key in _defaults:
|
|
|
|
if key in configuration["app"]:
|
|
|
|
configuration["app"][key] = _defaults[key] | configuration["app"][key]
|
|
|
|
else:
|
|
|
|
configuration["app"][key] = _defaults[key]
|
2022-05-10 20:34:29 +01:00
|
|
|
else:
|
|
|
|
configuration["app"] = _defaults
|
|
|
|
|
|
|
|
|
|
|
|
def get_configuration(key):
|
|
|
|
if key in configuration:
|
|
|
|
return configuration[key]
|
2023-06-26 16:08:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
def loader(kind_id):
|
|
|
|
configs = {}
|
|
|
|
userconfigpath = Path.home() / ".config" / "vm-compact" / "configs" / kind_id
|
|
|
|
if userconfigpath.exists():
|
|
|
|
filepaths = list(userconfigpath.glob("*.toml"))
|
|
|
|
for filepath in filepaths:
|
|
|
|
identifier = filepath.with_suffix("").stem
|
|
|
|
try:
|
|
|
|
with open(filepath, "rb") as f:
|
|
|
|
configs[identifier] = tomllib.load(f)
|
|
|
|
logger.info(f"loader: {identifier} loaded into memory")
|
|
|
|
except tomllib.TOMLDecodeError:
|
|
|
|
logger.error(f"Invalid TOML config: configs/{filename.stem}")
|
|
|
|
return configs
|