|
32 | 32 | # Regexes to remove dates and hashes in the filename that just get in the way |
33 | 33 | RE_DATE = r"(-\d{8}-)" |
34 | 34 | RE_HASH = r"(.g[0-9a-f]+\.)" |
35 | | -# regex to extract the version from the firmware filename |
36 | | -RE_VERSION_PREVIEW = r"(\d+\.\d+(\.\d+)?(-\w+.\d+)?)" |
| 35 | +# regex to extract the version and the build from the firmware filename |
| 36 | +# group 1 is the version, group 2 is the build |
| 37 | +RE_VERSION_PREVIEW = r"v([\d\.]+)-?(?:preview\.)?(\d+)?\." |
| 38 | +# 'RPI_PICO_W-v1.23.uf2' |
| 39 | +# 'RPI_PICO_W-v1.23.0.uf2' |
| 40 | +# 'RPI_PICO_W-v1.23.0-406.uf2' |
| 41 | +# 'RPI_PICO_W-v1.23.0-preview.406.uf2' |
| 42 | +# 'RPI_PICO_W-v1.23.0-preview.4.uf2' |
| 43 | +# 'RPI_PICO_W-v1.23.0.uf2' |
| 44 | +# 'https://micropython.org/resources/firmware/RPI_PICO_W-20240531-v1.24.0-preview.10.gc1a6b95bf.uf2' |
| 45 | +# 'https://micropython.org/resources/firmware/RPI_PICO_W-20240531-v1.24.0-preview.10.uf2' |
| 46 | +# 'RPI_PICO_W-v1.24.0-preview.10.gc1a6b95bf.uf2' |
37 | 47 |
|
38 | 48 |
|
39 | 49 | # use functools.lru_cache to avoid needing to download pages multiple times |
@@ -98,6 +108,7 @@ def board_firmware_urls(board_url: str, base_url: str, ext: str) -> List[str]: |
98 | 108 | # The first run takes ~60 seconds to run for 4 ports , all boards |
99 | 109 | # so it makes sense to cache the results and skip boards as soon as possible |
100 | 110 | def get_boards(ports: List[str], boards: List[str], clean: bool) -> List[FWInfo]: |
| 111 | + # sourcery skip: use-getitem-for-re-match-groups |
101 | 112 | """ |
102 | 113 | Retrieves a list of firmware information for the specified ports and boards. |
103 | 114 |
|
@@ -146,13 +157,15 @@ def get_boards(ports: List[str], boards: List[str], clean: bool) -> List[FWInfo] |
146 | 157 | # board["firmware"] = _url |
147 | 158 | # board["preview"] = "preview" in _url # type: ignore |
148 | 159 | if ver_match := re.search(RE_VERSION_PREVIEW, _url): |
149 | | - fw_info.version = ver_match[1] |
| 160 | + fw_info.version = ver_match.group(1) |
| 161 | + fw_info.build = ver_match.group(2) or "0" |
| 162 | + fw_info.preview = fw_info.build != "0" |
| 163 | + # # else: |
| 164 | + # # board.$1= "" |
| 165 | + # if "preview." in fw_info.version: |
| 166 | + # fw_info.build = fw_info.version.split("preview.")[-1] |
150 | 167 | # else: |
151 | | - # board.$1= "" |
152 | | - if "preview." in fw_info.version: |
153 | | - fw_info.build = fw_info.version.split("preview.")[-1] |
154 | | - else: |
155 | | - fw_info.build = "0" |
| 168 | + # fw_info.build = "0" |
156 | 169 |
|
157 | 170 | fw_info.ext = Path(fw_info.firmware).suffix |
158 | 171 | fw_info.variant = fw_info.filename.split("-v")[0] if "-v" in fw_info.filename else "" |
@@ -191,6 +204,11 @@ def download_firmwares( |
191 | 204 | # relevant |
192 | 205 |
|
193 | 206 | log.info(f"Found {len(unique_boards)} relevant unique firmwares") |
| 207 | + if not unique_boards: |
| 208 | + log.error("No relevant firmwares could be found on https://micropython.org/download") |
| 209 | + log.info(f"{versions=} {ports=} {boards=}") |
| 210 | + log.info("Please check the website for the latest firmware files or try the preview version.") |
| 211 | + return 0 |
194 | 212 |
|
195 | 213 | firmware_folder.mkdir(exist_ok=True) |
196 | 214 |
|
@@ -238,12 +256,15 @@ def get_firmware_list(ports: List[str], boards: List[str], versions: List[str], |
238 | 256 | board_urls = sorted(get_boards(ports, boards, clean), key=key_fw_ver_pre_ext_bld) |
239 | 257 |
|
240 | 258 | log.debug(f"Total {len(board_urls)} firmwares") |
| 259 | + |
241 | 260 | relevant = [ |
242 | 261 | board |
243 | 262 | for board in board_urls |
244 | | - if board.board in boards and (board.version in versions or board.preview and preview) |
245 | | - # and b["port"] in ["esp32", "rp2"] |
| 263 | + if board.version in versions and board.build == "0" and board.board in boards and not board.preview |
246 | 264 | ] |
| 265 | + |
| 266 | + if preview: |
| 267 | + relevant.extend([board for board in board_urls if board.board in boards and board.preview]) |
247 | 268 | log.debug(f"Matching firmwares: {len(relevant)}") |
248 | 269 | # select the unique boards |
249 | 270 | unique_boards: List[FWInfo] = [] |
|
0 commit comments