Skip to content

Commit

Permalink
mpflash: FIX version prefix mismatch in filtering downloaded firmwares
Browse files Browse the repository at this point in the history
  • Loading branch information
Josverl committed Jun 12, 2024
1 parent b78369f commit 8f3caa0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/mpflash/mpflash/downloaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def clean_downloaded_firmwares(fw_folder: Path) -> None:
writer.write(fw.to_dict())
log.info(f"Removed duplicate entries from firmware.jsonl in {fw_folder}")


def find_downloaded_firmware(
*,
board_id: str,
Expand All @@ -53,6 +54,7 @@ def find_downloaded_firmware(
selector = {}
fw_folder = fw_folder or config.firmware_folder
# Use the information in firmwares.jsonl to find the firmware file
log.debug(f"{trie}] Looking for firmware for {board_id} {version} ")
fw_list = downloaded_firmwares(fw_folder)
if not fw_list:
log.error("No firmware files found. Please download the firmware first.")
Expand Down Expand Up @@ -102,12 +104,13 @@ def filter_downloaded_fwlist(
fw_list = [fw for fw in fw_list if fw.preview]
else:
# FWInfo version has no v1.2.3 prefix
_version = clean_version(version, drop_v=True)
fw_list = [fw for fw in fw_list if fw.version == _version]

_version = {clean_version(version, drop_v=True), clean_version(version, drop_v=False)}
fw_list = [fw for fw in fw_list if fw.version in _version]
log.trace(f"Filtering firmware for {version} : {len(fw_list)} found.")
# filter by port
if port:
fw_list = [fw for fw in fw_list if fw.port == port]
log.trace(f"Filtering firmware for {port} : {len(fw_list)} found.")

if board_id:
if variants:
Expand All @@ -116,6 +119,7 @@ def filter_downloaded_fwlist(
else:
# the firmware variant should match exactly the board_id
fw_list = [fw for fw in fw_list if fw.variant == board_id]
log.trace(f"Filtering firmware for {board_id} : {len(fw_list)} found.")
if selector and port in selector:
fw_list = [fw for fw in fw_list if fw.filename.endswith(selector[port])]
return fw_list
Expand Down
3 changes: 2 additions & 1 deletion src/mpflash/mpflash/flash_uf2_boardid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path

from loguru import logger as log


Expand All @@ -10,5 +11,5 @@ def get_board_id(path: Path):
for line in data:
if line.startswith("Board-ID"):
board_id = line[9:].strip()
log.trace(f"Found Board-ID={board_id}")
log.debug(f"INFO_UF2.TXT Board-ID={board_id}")
return board_id
2 changes: 1 addition & 1 deletion src/mpflash/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mpflash"
version = "0.8.2"
version = "0.8.3"
description = "Flash and download tool for MicroPython firmwares"
authors = ["Jos Verlinde <jos_verlinde@hotmail.com>"]
license = "MIT"
Expand Down

0 comments on commit 8f3caa0

Please sign in to comment.