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