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
|
|
|
|
2022-04-11 18:35:28 +01:00
|
|
|
configuration = {}
|
|
|
|
|
|
|
|
config_path = [Path.cwd() / "configs"]
|
|
|
|
for path in config_path:
|
|
|
|
if path.is_dir():
|
|
|
|
filenames = list(path.glob("*.toml"))
|
|
|
|
configs = {}
|
|
|
|
for filename in filenames:
|
|
|
|
name = filename.with_suffix("").stem
|
|
|
|
try:
|
2022-06-16 23:53:28 +01:00
|
|
|
with open(filename, "rb") as f:
|
|
|
|
configs[name] = tomllib.load(f)
|
|
|
|
except tomllib.TOMLDecodeError:
|
2022-06-17 17:53:46 +01:00
|
|
|
print(f"Invalid TOML config: configs/{filename.stem}")
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
for name, cfg in configs.items():
|
2022-05-10 20:34:29 +01:00
|
|
|
print(f"Loaded configuration configs/{name}")
|
2022-04-11 18:35:28 +01:00
|
|
|
configuration[name] = cfg
|
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,
|
|
|
|
},
|
|
|
|
"mwscroll_step": {
|
|
|
|
"size": 3,
|
|
|
|
},
|
|
|
|
"submixes": {
|
|
|
|
"default": 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if "app" in configuration:
|
|
|
|
configuration["app"] = _defaults | configuration["app"]
|
|
|
|
else:
|
|
|
|
configuration["app"] = _defaults
|
|
|
|
|
|
|
|
|
|
|
|
def get_configuration(key):
|
|
|
|
if key in configuration:
|
|
|
|
return configuration[key]
|