Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/dev_manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Python functions can be added imported into `init` and `build` runlevels to exec
Within modules, all config values are imported, then processed according to the order of the `custom_parameters` list.

> If config values have validation which may fail if other config is not loaded, those values can be added to the `_late_args' list to be processed last.
`_module_name` can be set within a module for logging purposes, it is verified to be accurate when imported but optional.

## Imports
Expand Down
8 changes: 7 additions & 1 deletion src/ugrd/initramfs_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class InitramfsConfigDict(UserDict):
"custom_parameters": dict, # Custom parameters loaded from imports
"custom_processing": dict, # Custom processing functions which will be run to validate and process parameters
"_processing": dict, # A dict of queues containing parameters which have been set before the type was known
"_late_args": NoDupFlatList, # A list of arguments which could be passed as command line args but need to be processed after the config is loaded
"test_copy_config": NoDupFlatList, # A list of config values which are copied into test images, from the parent
}

Expand All @@ -57,7 +58,7 @@ def __init__(self, NO_BASE=False, *args, **kwargs):
else:
self["modules"] = "ugrd.base.core"

def import_args(self, args: dict, quiet=False) -> None:
def import_args(self, args: dict, quiet=False, late=False) -> None:
"""Imports data from an argument dict."""
log_level = 10 if quiet else 20
for arg, value in args.items():
Expand All @@ -66,6 +67,11 @@ def import_args(self, args: dict, quiet=False) -> None:
if arg == "modules": # allow loading modules by name from the command line
for module in value.split(","):
self[arg] = module
elif arg in self["_late_args"] and not late:
self.logger.debug(
f"[{c_(arg, 'yellow')}] Deferring late argument processing until after config load: {c_(value, 'green')}",
)
continue
elif getattr(self, arg, None) != value: # Only set the value if it differs:
self[arg] = value
else:
Expand Down
2 changes: 1 addition & 1 deletion src/ugrd/initramfs_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, config="/etc/ugrd/config.toml", *args, **kwargs):
try: # Attempt to load the config file, if it exists
self.load_config(config) # The user config is loaded over the base config, clobbering kwargs
self.config_dict.import_args(
kwargs, quiet=True
kwargs, quiet=True, late=True
) # Re-import kwargs (cmdline params) to apply them over the config
except FileNotFoundError:
if config: # If a config file was specified, log an error that it's missing
Expand Down
2 changes: 2 additions & 0 deletions src/ugrd/kmod/kmod.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ modules = [ "ugrd.kmod.standard_mask", "ugrd.kmod.platform", "ugrd.kmod.input" ]
kmod_pull_firmware = true
kmod_decompress_firmware = true

_late_args = ["kernel_version"]

[custom_parameters]
_kmod_removed = "NoDupFlatList" # Meant to be used internally, defines kernel modules which have been ignored at runtime
_kmod_modinfo = "dict" # Used internally, caches modinfo output for kernel modules
Expand Down