Add firmware/ directory and update file scanning logic
- Add firmware/ directory to hold firmware files for techs cloning the repo - Scan firmware/ (relative to script location) instead of CWD - Add .fwc to supported firmware extensions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,20 +25,22 @@ from ui import (
|
||||
# ── Firmware file selection helper ────────────────────────────────────────────
|
||||
def _prompt_fw_file(label: str) -> str:
|
||||
"""
|
||||
Scan the current working directory for firmware files and let the user
|
||||
pick one by number, or enter a custom path as the last option.
|
||||
Files are sorted most-recently-modified first.
|
||||
Scan the firmware/ directory (next to es24n_conf.py) for firmware files
|
||||
and let the user pick one by number, or enter a custom path as the last
|
||||
option. Files are sorted most-recently-modified first.
|
||||
"""
|
||||
cwd = os.getcwd()
|
||||
FW_EXTS = {".bin", ".img", ".fw", ".hex", ".zip", ".tar", ".tgz", ".gz"}
|
||||
fw_dir = os.path.normpath(
|
||||
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "firmware")
|
||||
)
|
||||
FW_EXTS = {".bin", ".img", ".fw", ".fwc", ".hex", ".zip", ".tar", ".tgz", ".gz"}
|
||||
|
||||
try:
|
||||
candidates = sorted(
|
||||
[f for f in os.listdir(cwd)
|
||||
[f for f in os.listdir(fw_dir)
|
||||
if not f.startswith(".")
|
||||
and os.path.isfile(os.path.join(cwd, f))
|
||||
and os.path.isfile(os.path.join(fw_dir, f))
|
||||
and os.path.splitext(f)[1].lower() in FW_EXTS],
|
||||
key=lambda f: os.path.getmtime(os.path.join(cwd, f)),
|
||||
key=lambda f: os.path.getmtime(os.path.join(fw_dir, f)),
|
||||
reverse=True,
|
||||
)
|
||||
except OSError:
|
||||
@@ -46,9 +48,9 @@ def _prompt_fw_file(label: str) -> str:
|
||||
|
||||
print()
|
||||
if candidates:
|
||||
info(f"Firmware files found in {cwd}:")
|
||||
info(f"Firmware files found in {fw_dir}:")
|
||||
for i, fname in enumerate(candidates, 1):
|
||||
sz = os.path.getsize(os.path.join(cwd, fname))
|
||||
sz = os.path.getsize(os.path.join(fw_dir, fname))
|
||||
print(f" {_c(C.BOLD, str(i))} {fname} {_c(C.DIM, f'({sz // 1024} KB)')}")
|
||||
custom_idx = len(candidates) + 1
|
||||
print(f" {_c(C.BOLD, str(custom_idx))} Enter a custom file path")
|
||||
@@ -59,7 +61,7 @@ def _prompt_fw_file(label: str) -> str:
|
||||
if choice.isdigit():
|
||||
idx = int(choice)
|
||||
if 1 <= idx <= len(candidates):
|
||||
path = os.path.join(cwd, candidates[idx - 1])
|
||||
path = os.path.join(fw_dir, candidates[idx - 1])
|
||||
sz = os.path.getsize(path)
|
||||
ok(f"Selected: {candidates[idx - 1]} ({sz // 1024} KB)")
|
||||
return path
|
||||
@@ -67,7 +69,7 @@ def _prompt_fw_file(label: str) -> str:
|
||||
break
|
||||
warn(f"Please enter a number between 1 and {custom_idx}.")
|
||||
else:
|
||||
info(f"No firmware files found in {cwd}.")
|
||||
info(f"No firmware files found in {fw_dir}.")
|
||||
|
||||
# Manual path entry
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user