Skip to content

Conversation

Salamandar
Copy link

Closes #68

paths-relative-to can be CWD, THIS_FILE, or a literal path. It defaults
to CWD.

The firmware configs will be patched accordingly: binary paths will be
prefixed by either the current working directory (this is the old
behaviour), the directory containing the firmware config file, or the
literal path.

Let me know if you prefer the CWD behaviour to do nothing (like the current behaviour) instead of prefixing with os.getcwd().

… final fw_configs

fw_configs will always be a dictionnary, but individual ones might not.
configs

paths-relative-to can be CWD, THIS_FILE, or a literal path. It defaults
to CWD.

The firmware configs will be patched accordingly: binary paths will be
prefixed by either the current working directory (this is the old
behaviour), the directory containing the firmware config file, or the
literal path.
Copy link
Collaborator

@rgantois rgantois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I've requested a few changes. There's also a linter error, so you might want to run "ruff check" on your sources.

def patch_firmware_image_paths(fw_config: dict, this_file_path: str) -> dict:
paths_relative_to_conf = fw_config.pop("paths-relative-to", "CWD")
if paths_relative_to_conf == "CWD":
path_relative_to = os.getcwd()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in your PR message, I'd prefer we didn't modify the path at all if "CWD" is specified. I'm pretty sure it wouldn't change anything but I'd rather not take an unnecessary risk.

@@ -76,6 +77,20 @@ def check_soc_model(soc_model: str):
return None


def patch_firmware_image_paths(fw_config: dict, this_file_path: str) -> dict:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't actually need to return anything. It just modifies the dict in-place.

@@ -76,6 +77,20 @@ def check_soc_model(soc_model: str):
return None


def patch_firmware_image_paths(fw_config: dict, this_file_path: str) -> dict:
paths_relative_to_conf = fw_config.pop("paths-relative-to", "CWD")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a user interface change, so it needs to be documented. You can describe this configuration option in docs/fw_binaries.md, in the introduction section.

@@ -127,6 +142,7 @@ def init_config(args: list):
cli_error(
f"firmware config passed to CLI did not evaluate to dict: {fw_configs}"
)
fw_config_file = patch_firmware_image_paths(fw_config_file, path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd prefer "complete_fw_paths()"
also, as mentioned above, this function doesn't return anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

snagrecover firmwares.yml: firmware paths should allow relative paths from firmwares.yml
2 participants