feat(config): Config loading and merging
This commit is contained in:
+49
-2
@@ -12,20 +12,67 @@ def _load_config_file(file: str):
|
||||
return parsed
|
||||
|
||||
|
||||
def default_config() -> ArchMgrConfig:
|
||||
return {
|
||||
"pkgs": {
|
||||
"individual": [],
|
||||
"bundles": [],
|
||||
"repos": {
|
||||
"enabled_repos": [
|
||||
{
|
||||
"name": "core",
|
||||
"setup_cmds": [],
|
||||
"mirrors": {"use_default": True, "extra_mirrors": []},
|
||||
}
|
||||
],
|
||||
"reflector": {
|
||||
"enabled": False,
|
||||
"count": 0,
|
||||
"countries": [],
|
||||
"interval": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
"boot": {
|
||||
"managed": False,
|
||||
"bootloader": "grub",
|
||||
"esp_dir": "/boot",
|
||||
"os_prober": False,
|
||||
"theme_folder": "/usr/share/themes/grub",
|
||||
},
|
||||
"cmds": {"always": [], "once": []},
|
||||
"git": {
|
||||
"repos": [],
|
||||
"creds": {"manager": "git-credential-manager"},
|
||||
},
|
||||
"users": [],
|
||||
"symlinks": [],
|
||||
"template_data": [],
|
||||
"themes": {
|
||||
"cursor_theme": "oreo_spark_blue_cursor",
|
||||
"font": "Comfortaa 11",
|
||||
"gtk": "Adaptive-Theme",
|
||||
"qt": "gtk3",
|
||||
"icon_theme": "candy-icons"
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def load_config(file: str) -> ArchMgrConfig:
|
||||
# Load and validate initial config
|
||||
try:
|
||||
loaded_conf = _load_config_file(file)
|
||||
except Exception:
|
||||
return {}
|
||||
return default_config()
|
||||
if not validator.validate(loaded_conf):
|
||||
return {}
|
||||
return default_config()
|
||||
|
||||
configuration = cast(dict[str, Any], loaded_conf)
|
||||
requires = cast(list[str], configuration.pop("requires"))
|
||||
conf = cast(ArchMgrConfig, configuration)
|
||||
|
||||
# Recursively load files
|
||||
print("Requires", requires)
|
||||
for conf_file in requires:
|
||||
conf = merge_configs(conf, load_config(conf_file))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user