Skip to content

Commit a3804c3

Browse files
committed
snagrecover: config: Allow a 'paths-relative-to' key in the firmware
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.
1 parent 2c74d21 commit a3804c3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/snagrecover/config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# along with this program; if not, write to the Free Software
1818
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919

20+
import os
2021
import yaml
2122
from snagrecover.utils import (
2223
cli_error,
@@ -76,6 +77,20 @@ def check_soc_model(soc_model: str):
7677
return None
7778

7879

80+
def patch_firmware_image_paths(fw_config: dict, this_file_path: str) -> dict:
81+
paths_relative_to_conf = fw_config.pop("paths-relative-to", "CWD")
82+
if paths_relative_to_conf == "CWD":
83+
path_relative_to = os.getcwd()
84+
elif paths_relative_to_conf == "THIS_FILE":
85+
path_relative_to = os.path.dirname(this_file_path)
86+
else:
87+
path_relative_to = path_relative_to_conf
88+
89+
for binary in fw_config.keys():
90+
if "path" in fw_config[binary]:
91+
fw_config[binary]["path"] = os.path.join(path_relative_to, fw_config[binary]["path"])
92+
93+
7994
def init_config(args: list):
8095
# this is the only time that config.recovery_config should be modified!
8196
# get soc model
@@ -127,6 +142,7 @@ def init_config(args: list):
127142
cli_error(
128143
f"firmware config passed to CLI did not evaluate to dict: {fw_configs}"
129144
)
145+
fw_config_file = patch_firmware_image_paths(fw_config_file, path)
130146
fw_configs = {**fw_configs, **fw_config_file}
131147
recovery_config["firmware"] = fw_configs
132148

0 commit comments

Comments
 (0)