configpaths added to configurations

This commit is contained in:
onyx-and-iris 2023-06-26 13:53:38 +01:00
parent 5ccc2a6dab
commit fc20bb0c1e

View File

@ -6,26 +6,32 @@ try:
except ModuleNotFoundError:
import tomli as tomllib
LOGGER = logging.getLogger("configurations")
logger = logging.getLogger(__name__)
configuration = {}
config_path = [Path.cwd() / "configs"]
for path in config_path:
if path.is_dir():
filenames = list(path.glob("*.toml"))
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 filename in filenames:
name = filename.with_suffix("").stem
for filepath in filepaths:
filename = filepath.with_suffix("").stem
if filename in ("app", "vban"):
try:
with open(filename, "rb") as f:
configs[name] = tomllib.load(f)
with open(filepath, "rb") as f:
configs[filename] = tomllib.load(f)
logger.info(f"{filename} loaded into memory")
except tomllib.TOMLDecodeError:
print(f"Invalid TOML config: configs/{filename.stem}")
logger.error(f"Invalid TOML config: configs/{filename.stem}")
for name, cfg in configs.items():
LOGGER.info(f"Loaded configuration configs/{name}")
configuration[name] = cfg
configuration |= configs
break
_defaults = {
"configs": {