micropython-stubber 1.20.5__py3-none-any.whl → 1.20.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/LICENSE +30 -30
- {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/METADATA +1 -1
- micropython_stubber-1.20.6.dist-info/RECORD +159 -0
- mpflash/README.md +184 -184
- mpflash/libusb_flash.ipynb +203 -203
- mpflash/mpflash/add_firmware.py +98 -98
- mpflash/mpflash/ask_input.py +236 -236
- mpflash/mpflash/bootloader/__init__.py +37 -36
- mpflash/mpflash/bootloader/manual.py +102 -102
- mpflash/mpflash/bootloader/micropython.py +10 -10
- mpflash/mpflash/bootloader/touch1200.py +45 -45
- mpflash/mpflash/cli_download.py +129 -129
- mpflash/mpflash/cli_flash.py +219 -219
- mpflash/mpflash/cli_group.py +98 -98
- mpflash/mpflash/cli_list.py +81 -81
- mpflash/mpflash/cli_main.py +41 -41
- mpflash/mpflash/common.py +164 -164
- mpflash/mpflash/config.py +47 -47
- mpflash/mpflash/connected.py +74 -74
- mpflash/mpflash/download.py +360 -360
- mpflash/mpflash/downloaded.py +129 -129
- mpflash/mpflash/errors.py +9 -9
- mpflash/mpflash/flash.py +52 -52
- mpflash/mpflash/flash_esp.py +59 -59
- mpflash/mpflash/flash_stm32.py +24 -24
- mpflash/mpflash/flash_stm32_cube.py +111 -111
- mpflash/mpflash/flash_stm32_dfu.py +101 -101
- mpflash/mpflash/flash_uf2.py +67 -67
- mpflash/mpflash/flash_uf2_boardid.py +15 -15
- mpflash/mpflash/flash_uf2_linux.py +123 -123
- mpflash/mpflash/flash_uf2_macos.py +34 -34
- mpflash/mpflash/flash_uf2_windows.py +34 -34
- mpflash/mpflash/list.py +89 -89
- mpflash/mpflash/logger.py +41 -41
- mpflash/mpflash/mpboard_id/__init__.py +93 -93
- mpflash/mpflash/mpboard_id/add_boards.py +255 -255
- mpflash/mpflash/mpboard_id/board.py +37 -37
- mpflash/mpflash/mpboard_id/board_id.py +86 -86
- mpflash/mpflash/mpboard_id/store.py +43 -43
- mpflash/mpflash/mpremoteboard/__init__.py +221 -221
- mpflash/mpflash/mpremoteboard/mpy_fw_info.py +141 -141
- mpflash/mpflash/mpremoteboard/runner.py +140 -140
- mpflash/mpflash/uf2disk.py +12 -12
- mpflash/mpflash/vendor/basicgit.py +288 -288
- mpflash/mpflash/vendor/click_aliases.py +91 -91
- mpflash/mpflash/vendor/dfu.py +165 -165
- mpflash/mpflash/vendor/pydfu.py +605 -605
- mpflash/mpflash/vendor/readme.md +2 -2
- mpflash/mpflash/vendor/versions.py +119 -117
- mpflash/mpflash/worklist.py +170 -170
- mpflash/poetry.lock +1588 -1588
- mpflash/pyproject.toml +60 -60
- mpflash/stm32_udev_rules.md +62 -62
- stubber/__init__.py +3 -3
- stubber/basicgit.py +294 -288
- stubber/board/board_info.csv +193 -193
- stubber/board/boot.py +34 -34
- stubber/board/createstubs.py +986 -986
- stubber/board/createstubs_db.py +825 -825
- stubber/board/createstubs_db_min.py +331 -331
- stubber/board/createstubs_db_mpy.mpy +0 -0
- stubber/board/createstubs_lvgl.py +741 -741
- stubber/board/createstubs_lvgl_min.py +741 -741
- stubber/board/createstubs_mem.py +766 -766
- stubber/board/createstubs_mem_min.py +306 -306
- stubber/board/createstubs_mem_mpy.mpy +0 -0
- stubber/board/createstubs_min.py +294 -294
- stubber/board/createstubs_mpy.mpy +0 -0
- stubber/board/fw_info.py +141 -141
- stubber/board/info.py +183 -183
- stubber/board/main.py +19 -19
- stubber/board/modulelist.txt +247 -247
- stubber/board/pyrightconfig.json +34 -34
- stubber/bulk/mcu_stubber.py +454 -454
- stubber/codemod/_partials/__init__.py +48 -48
- stubber/codemod/_partials/db_main.py +147 -147
- stubber/codemod/_partials/lvgl_main.py +77 -77
- stubber/codemod/_partials/modules_reader.py +80 -80
- stubber/codemod/add_comment.py +53 -53
- stubber/codemod/add_method.py +65 -65
- stubber/codemod/board.py +317 -317
- stubber/codemod/enrich.py +145 -145
- stubber/codemod/merge_docstub.py +284 -284
- stubber/codemod/modify_list.py +54 -54
- stubber/codemod/utils.py +57 -57
- stubber/commands/build_cmd.py +94 -94
- stubber/commands/cli.py +51 -51
- stubber/commands/clone_cmd.py +66 -66
- stubber/commands/config_cmd.py +29 -29
- stubber/commands/enrich_folder_cmd.py +70 -70
- stubber/commands/get_core_cmd.py +69 -69
- stubber/commands/get_docstubs_cmd.py +87 -87
- stubber/commands/get_frozen_cmd.py +112 -112
- stubber/commands/get_mcu_cmd.py +56 -56
- stubber/commands/merge_cmd.py +66 -66
- stubber/commands/publish_cmd.py +119 -119
- stubber/commands/stub_cmd.py +30 -30
- stubber/commands/switch_cmd.py +54 -54
- stubber/commands/variants_cmd.py +48 -48
- stubber/cst_transformer.py +178 -178
- stubber/data/board_info.csv +193 -193
- stubber/data/board_info.json +1729 -1729
- stubber/data/micropython_tags.csv +15 -15
- stubber/data/requirements-core-micropython.txt +38 -38
- stubber/data/requirements-core-pycopy.txt +39 -39
- stubber/downloader.py +36 -36
- stubber/freeze/common.py +68 -68
- stubber/freeze/freeze_folder.py +69 -69
- stubber/freeze/freeze_manifest_2.py +113 -113
- stubber/freeze/get_frozen.py +127 -127
- stubber/get_cpython.py +101 -101
- stubber/get_lobo.py +59 -59
- stubber/minify.py +418 -418
- stubber/publish/bump.py +86 -86
- stubber/publish/candidates.py +262 -262
- stubber/publish/database.py +18 -18
- stubber/publish/defaults.py +45 -45
- stubber/publish/enums.py +24 -24
- stubber/publish/helpers.py +29 -29
- stubber/publish/merge_docstubs.py +130 -130
- stubber/publish/missing_class_methods.py +49 -49
- stubber/publish/package.py +146 -146
- stubber/publish/pathnames.py +51 -51
- stubber/publish/publish.py +120 -120
- stubber/publish/pypi.py +38 -38
- stubber/publish/stubpackage.py +1029 -1029
- stubber/rst/__init__.py +9 -9
- stubber/rst/classsort.py +77 -77
- stubber/rst/lookup.py +530 -530
- stubber/rst/output_dict.py +401 -401
- stubber/rst/reader.py +822 -822
- stubber/rst/report_return.py +69 -69
- stubber/rst/rst_utils.py +540 -540
- stubber/stubber.py +38 -38
- stubber/stubs_from_docs.py +90 -90
- stubber/tools/manifestfile.py +610 -610
- stubber/tools/readme.md +5 -5
- stubber/update_fallback.py +117 -117
- stubber/update_module_list.py +123 -123
- stubber/utils/__init__.py +5 -5
- stubber/utils/config.py +127 -127
- stubber/utils/makeversionhdr.py +54 -54
- stubber/utils/manifest.py +92 -92
- stubber/utils/post.py +79 -79
- stubber/utils/repos.py +157 -154
- stubber/utils/stubmaker.py +139 -139
- stubber/utils/typed_config_toml.py +77 -77
- stubber/utils/versions.py +128 -120
- stubber/variants.py +106 -106
- micropython_stubber-1.20.5.dist-info/RECORD +0 -159
- {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/WHEEL +0 -0
- {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/entry_points.txt +0 -0
mpflash/mpflash/vendor/readme.md
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
These modules are vendored from the following repositories:
|
2
|
-
|
1
|
+
These modules are vendored from the following repositories:
|
2
|
+
|
3
3
|
micropython/micropython
|
@@ -1,117 +1,119 @@
|
|
1
|
-
"""
|
2
|
-
#############################################################
|
3
|
-
# Version handling copied from stubber/utils/versions.py
|
4
|
-
#############################################################
|
5
|
-
"""
|
6
|
-
|
7
|
-
from functools import lru_cache
|
8
|
-
|
9
|
-
from loguru import logger as log
|
10
|
-
from packaging.version import parse
|
11
|
-
|
12
|
-
from mpflash.common import GH_CLIENT
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
if version
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
version =
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
version = V_PREVIEW
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
version = version.strip().replace("
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
version = "v"
|
66
|
-
|
67
|
-
version =
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
versions = [
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
"
|
85
|
-
"v1.
|
86
|
-
"v1.
|
87
|
-
"v1.
|
88
|
-
"v1.
|
89
|
-
"v1.
|
90
|
-
"v1.
|
91
|
-
"v1.
|
92
|
-
"v1.
|
93
|
-
"v1.
|
94
|
-
"v1.
|
95
|
-
"v1.
|
96
|
-
"v1.
|
97
|
-
"v1.
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
1
|
+
"""
|
2
|
+
#############################################################
|
3
|
+
# Version handling copied from stubber/utils/versions.py
|
4
|
+
#############################################################
|
5
|
+
"""
|
6
|
+
|
7
|
+
from functools import lru_cache
|
8
|
+
|
9
|
+
from loguru import logger as log
|
10
|
+
from packaging.version import parse
|
11
|
+
|
12
|
+
from mpflash.common import GH_CLIENT
|
13
|
+
OLDEST_VERSION = "1.16"
|
14
|
+
"This is the oldest MicroPython version to build the stubs on"
|
15
|
+
|
16
|
+
V_PREVIEW = "preview"
|
17
|
+
"Latest preview version"
|
18
|
+
|
19
|
+
SET_PREVIEW = {"preview", "latest", "master"}
|
20
|
+
|
21
|
+
|
22
|
+
def clean_version(
|
23
|
+
version: str,
|
24
|
+
*,
|
25
|
+
build: bool = False,
|
26
|
+
patch: bool = False,
|
27
|
+
commit: bool = False,
|
28
|
+
drop_v: bool = False,
|
29
|
+
flat: bool = False,
|
30
|
+
):
|
31
|
+
"Clean up and transform the many flavours of versions"
|
32
|
+
# 'v1.13.0-103-gb137d064e' --> 'v1.13-103'
|
33
|
+
if version in {"", "-"}:
|
34
|
+
return version
|
35
|
+
if version.lower() == "stable":
|
36
|
+
_v = get_stable_mp_version()
|
37
|
+
if not _v:
|
38
|
+
log.warning("Could not determine the latest stable version")
|
39
|
+
return "stable"
|
40
|
+
version = _v
|
41
|
+
log.trace(f"Using latest stable version: {version}")
|
42
|
+
is_preview = "-preview" in version
|
43
|
+
nibbles = version.split("-")
|
44
|
+
ver_ = nibbles[0].lower().lstrip("v")
|
45
|
+
if not patch and ver_ >= "1.10.0" and ver_ < "1.20.0" and ver_.endswith(".0"):
|
46
|
+
# remove the last ".0" - but only for versions between 1.10 and 1.20 (because)
|
47
|
+
nibbles[0] = nibbles[0][:-2]
|
48
|
+
if len(nibbles) == 1:
|
49
|
+
version = nibbles[0]
|
50
|
+
elif build and not is_preview:
|
51
|
+
version = "-".join(nibbles) if commit else "-".join(nibbles[:-1])
|
52
|
+
else:
|
53
|
+
# version = "-".join((nibbles[0], LATEST))
|
54
|
+
# HACK: this is not always right, but good enough most of the time
|
55
|
+
if is_preview:
|
56
|
+
version = "-".join((nibbles[0], V_PREVIEW))
|
57
|
+
else:
|
58
|
+
version = V_PREVIEW
|
59
|
+
if flat:
|
60
|
+
version = version.strip().replace(".", "_").replace("-", "_")
|
61
|
+
else:
|
62
|
+
version = version.strip().replace("_preview", "-preview").replace("_", ".")
|
63
|
+
|
64
|
+
if drop_v:
|
65
|
+
version = version.lstrip("v")
|
66
|
+
elif not version.startswith("v") and version.lower() not in SET_PREVIEW:
|
67
|
+
version = "v" + version
|
68
|
+
if version in SET_PREVIEW:
|
69
|
+
version = V_PREVIEW
|
70
|
+
return version
|
71
|
+
|
72
|
+
|
73
|
+
@lru_cache(maxsize=10)
|
74
|
+
def micropython_versions(minver: str = "v1.20", reverse: bool = False):
|
75
|
+
"""Get the list of micropython versions from github tags"""
|
76
|
+
try:
|
77
|
+
gh_client = GH_CLIENT
|
78
|
+
repo = gh_client.get_repo("micropython/micropython")
|
79
|
+
versions = [tag.name for tag in repo.get_tags() if parse(tag.name) >= parse(minver)]
|
80
|
+
# Only keep the last preview
|
81
|
+
versions = [v for v in versions if not v.endswith(V_PREVIEW) or v == versions[-1]]
|
82
|
+
except Exception:
|
83
|
+
versions = [
|
84
|
+
"v9.99.9-preview",
|
85
|
+
"v1.22.2",
|
86
|
+
"v1.22.1",
|
87
|
+
"v1.22.0",
|
88
|
+
"v1.21.1",
|
89
|
+
"v1.21.0",
|
90
|
+
"v1.20.0",
|
91
|
+
"v1.19.1",
|
92
|
+
"v1.19",
|
93
|
+
"v1.18",
|
94
|
+
"v1.17",
|
95
|
+
"v1.16",
|
96
|
+
"v1.15",
|
97
|
+
"v1.14",
|
98
|
+
"v1.13",
|
99
|
+
"v1.12",
|
100
|
+
"v1.11",
|
101
|
+
"v1.10",
|
102
|
+
]
|
103
|
+
versions = [v for v in versions if parse(v) >= parse(minver)]
|
104
|
+
# remove all but the most recent (preview) version
|
105
|
+
versions = versions[:1] + [v for v in versions if "preview" not in v]
|
106
|
+
return sorted(versions, reverse=reverse)
|
107
|
+
|
108
|
+
|
109
|
+
def get_stable_mp_version() -> str:
|
110
|
+
# read the versions from the git tags
|
111
|
+
all_versions = micropython_versions(minver=OLDEST_VERSION)
|
112
|
+
return [v for v in all_versions if not v.endswith(V_PREVIEW)][-1]
|
113
|
+
|
114
|
+
|
115
|
+
def get_preview_mp_version() -> str:
|
116
|
+
# read the versions from the git tags
|
117
|
+
all_versions = micropython_versions(minver=OLDEST_VERSION)
|
118
|
+
return [v for v in all_versions if v.endswith(V_PREVIEW)][-1]
|
119
|
+
|
mpflash/mpflash/worklist.py
CHANGED
@@ -1,170 +1,170 @@
|
|
1
|
-
from pathlib import Path
|
2
|
-
from typing import Dict, List, Optional, Tuple
|
3
|
-
|
4
|
-
from loguru import logger as log
|
5
|
-
|
6
|
-
from mpflash.common import FWInfo, filtered_comports
|
7
|
-
from mpflash.errors import MPFlashError
|
8
|
-
|
9
|
-
from .downloaded import find_downloaded_firmware
|
10
|
-
from .list import show_mcus
|
11
|
-
from .mpboard_id import find_known_board
|
12
|
-
from .mpremoteboard import MPRemoteBoard
|
13
|
-
|
14
|
-
# #########################################################################################################
|
15
|
-
WorkList = List[Tuple[MPRemoteBoard, FWInfo]]
|
16
|
-
# #########################################################################################################
|
17
|
-
|
18
|
-
|
19
|
-
def auto_update(
|
20
|
-
conn_boards: List[MPRemoteBoard],
|
21
|
-
target_version: str,
|
22
|
-
fw_folder: Path,
|
23
|
-
*,
|
24
|
-
selector: Optional[Dict[str, str]] = None,
|
25
|
-
) -> WorkList:
|
26
|
-
"""Builds a list of boards to update based on the connected boards and the firmwares available locally in the firmware folder.
|
27
|
-
|
28
|
-
Args:
|
29
|
-
conn_boards (List[MPRemoteBoard]): List of connected boards
|
30
|
-
target_version (str): Target firmware version
|
31
|
-
fw_folder (Path): Path to the firmware folder
|
32
|
-
selector (Optional[Dict[str, str]], optional): Selector for filtering firmware. Defaults to None.
|
33
|
-
|
34
|
-
Returns:
|
35
|
-
WorkList: List of boards and firmware information to update
|
36
|
-
"""
|
37
|
-
if selector is None:
|
38
|
-
selector = {}
|
39
|
-
wl: WorkList = []
|
40
|
-
for mcu in conn_boards:
|
41
|
-
if mcu.family not in ("micropython", "unknown"):
|
42
|
-
log.warning(
|
43
|
-
f"Skipping flashing {mcu.family} {mcu.port} {mcu.board} on {mcu.serialport} as it is not a MicroPython firmware"
|
44
|
-
)
|
45
|
-
continue
|
46
|
-
board_firmwares = find_downloaded_firmware(
|
47
|
-
fw_folder=fw_folder,
|
48
|
-
board_id=mcu.board,
|
49
|
-
version=target_version,
|
50
|
-
port=mcu.port,
|
51
|
-
selector=selector,
|
52
|
-
)
|
53
|
-
|
54
|
-
if not board_firmwares:
|
55
|
-
log.error(f"No {target_version} firmware found for {mcu.board} on {mcu.serialport}.")
|
56
|
-
continue
|
57
|
-
if len(board_firmwares) > 1:
|
58
|
-
log.debug(f"Multiple {target_version} firmwares found for {mcu.board} on {mcu.serialport}.")
|
59
|
-
|
60
|
-
# just use the last firmware
|
61
|
-
fw_info = board_firmwares[-1]
|
62
|
-
log.info(f"Found {target_version} firmware {fw_info.filename} for {mcu.board} on {mcu.serialport}.")
|
63
|
-
wl.append((mcu, fw_info))
|
64
|
-
return wl
|
65
|
-
|
66
|
-
|
67
|
-
def manual_worklist(
|
68
|
-
serial: str,
|
69
|
-
*,
|
70
|
-
board_id: str,
|
71
|
-
version: str,
|
72
|
-
fw_folder: Path,
|
73
|
-
) -> WorkList:
|
74
|
-
"""Create a worklist for a single board specified manually.
|
75
|
-
|
76
|
-
Args:
|
77
|
-
serial (str): Serial port of the board
|
78
|
-
board (str): Board_ID
|
79
|
-
version (str): Firmware version
|
80
|
-
fw_folder (Path): Path to the firmware folder
|
81
|
-
|
82
|
-
Returns:
|
83
|
-
WorkList: List of boards and firmware information to update
|
84
|
-
"""
|
85
|
-
log.trace(f"Manual updating {serial} to {board_id} {version}")
|
86
|
-
mcu = MPRemoteBoard(serial)
|
87
|
-
# Lookup the matching port and cpu in board_info based in the board name
|
88
|
-
try:
|
89
|
-
info = find_known_board(board_id)
|
90
|
-
mcu.port = info.port
|
91
|
-
# need the CPU type for the esptool
|
92
|
-
mcu.cpu = info.cpu
|
93
|
-
except (LookupError, MPFlashError) as e:
|
94
|
-
log.error(f"Board {board_id} not found in board_info.zip")
|
95
|
-
log.exception(e)
|
96
|
-
return []
|
97
|
-
mcu.board = board_id
|
98
|
-
firmwares = find_downloaded_firmware(fw_folder=fw_folder, board_id=board_id, version=version, port=mcu.port)
|
99
|
-
if not firmwares:
|
100
|
-
log.error(f"No firmware found for {mcu.port} {board_id} version {version}")
|
101
|
-
return []
|
102
|
-
# use the most recent matching firmware
|
103
|
-
return [(mcu, firmwares[-1])] # type: ignore
|
104
|
-
|
105
|
-
|
106
|
-
def single_auto_worklist(
|
107
|
-
serial: str,
|
108
|
-
*,
|
109
|
-
version: str,
|
110
|
-
fw_folder: Path,
|
111
|
-
) -> WorkList:
|
112
|
-
"""Create a worklist for a single serial-port.
|
113
|
-
|
114
|
-
Args:
|
115
|
-
serial_port (str): Serial port of the board
|
116
|
-
version (str): Firmware version
|
117
|
-
fw_folder (Path): Path to the firmware folder
|
118
|
-
|
119
|
-
Returns:
|
120
|
-
WorkList: List of boards and firmware information to update
|
121
|
-
"""
|
122
|
-
log.trace(f"Auto updating {serial} to {version}")
|
123
|
-
conn_boards = [MPRemoteBoard(serial)]
|
124
|
-
todo = auto_update(conn_boards, version, fw_folder) # type: ignore # List / list
|
125
|
-
show_mcus(conn_boards) # type: ignore
|
126
|
-
return todo
|
127
|
-
|
128
|
-
|
129
|
-
def full_auto_worklist(
|
130
|
-
all_boards: List[MPRemoteBoard], *, include: List[str], ignore: List[str], version: str, fw_folder: Path
|
131
|
-
) -> WorkList:
|
132
|
-
"""
|
133
|
-
Create a worklist for all connected micropython boards based on the information retrieved from the board.
|
134
|
-
This allows the firmware version of one or moae boards to be changed without needing to specify the port or board_id manually.
|
135
|
-
|
136
|
-
Args:
|
137
|
-
version (str): Firmware version
|
138
|
-
fw_folder (Path): Path to the firmware folder
|
139
|
-
|
140
|
-
Returns:
|
141
|
-
WorkList: List of boards and firmware information to update
|
142
|
-
"""
|
143
|
-
log.trace(f"Auto updating all boards to {version}")
|
144
|
-
if selected_boards := filter_boards(all_boards, include=include, ignore=ignore):
|
145
|
-
return auto_update(selected_boards, version, fw_folder)
|
146
|
-
else:
|
147
|
-
return []
|
148
|
-
|
149
|
-
|
150
|
-
def filter_boards(
|
151
|
-
all_boards: List[MPRemoteBoard],
|
152
|
-
*,
|
153
|
-
include: List[str],
|
154
|
-
ignore: List[str],
|
155
|
-
):
|
156
|
-
try:
|
157
|
-
comports = [
|
158
|
-
p.device
|
159
|
-
for p in filtered_comports(
|
160
|
-
ignore=ignore,
|
161
|
-
include=include,
|
162
|
-
bluetooth=False,
|
163
|
-
)
|
164
|
-
]
|
165
|
-
selected_boards = [b for b in all_boards if b.serialport in comports]
|
166
|
-
# [MPRemoteBoard(port.device, update=True) for port in comports]
|
167
|
-
except ConnectionError as e:
|
168
|
-
log.error(f"Error connecting to boards: {e}")
|
169
|
-
return []
|
170
|
-
return selected_boards # type: ignore
|
1
|
+
from pathlib import Path
|
2
|
+
from typing import Dict, List, Optional, Tuple
|
3
|
+
|
4
|
+
from loguru import logger as log
|
5
|
+
|
6
|
+
from mpflash.common import FWInfo, filtered_comports
|
7
|
+
from mpflash.errors import MPFlashError
|
8
|
+
|
9
|
+
from .downloaded import find_downloaded_firmware
|
10
|
+
from .list import show_mcus
|
11
|
+
from .mpboard_id import find_known_board
|
12
|
+
from .mpremoteboard import MPRemoteBoard
|
13
|
+
|
14
|
+
# #########################################################################################################
|
15
|
+
WorkList = List[Tuple[MPRemoteBoard, FWInfo]]
|
16
|
+
# #########################################################################################################
|
17
|
+
|
18
|
+
|
19
|
+
def auto_update(
|
20
|
+
conn_boards: List[MPRemoteBoard],
|
21
|
+
target_version: str,
|
22
|
+
fw_folder: Path,
|
23
|
+
*,
|
24
|
+
selector: Optional[Dict[str, str]] = None,
|
25
|
+
) -> WorkList:
|
26
|
+
"""Builds a list of boards to update based on the connected boards and the firmwares available locally in the firmware folder.
|
27
|
+
|
28
|
+
Args:
|
29
|
+
conn_boards (List[MPRemoteBoard]): List of connected boards
|
30
|
+
target_version (str): Target firmware version
|
31
|
+
fw_folder (Path): Path to the firmware folder
|
32
|
+
selector (Optional[Dict[str, str]], optional): Selector for filtering firmware. Defaults to None.
|
33
|
+
|
34
|
+
Returns:
|
35
|
+
WorkList: List of boards and firmware information to update
|
36
|
+
"""
|
37
|
+
if selector is None:
|
38
|
+
selector = {}
|
39
|
+
wl: WorkList = []
|
40
|
+
for mcu in conn_boards:
|
41
|
+
if mcu.family not in ("micropython", "unknown"):
|
42
|
+
log.warning(
|
43
|
+
f"Skipping flashing {mcu.family} {mcu.port} {mcu.board} on {mcu.serialport} as it is not a MicroPython firmware"
|
44
|
+
)
|
45
|
+
continue
|
46
|
+
board_firmwares = find_downloaded_firmware(
|
47
|
+
fw_folder=fw_folder,
|
48
|
+
board_id=mcu.board,
|
49
|
+
version=target_version,
|
50
|
+
port=mcu.port,
|
51
|
+
selector=selector,
|
52
|
+
)
|
53
|
+
|
54
|
+
if not board_firmwares:
|
55
|
+
log.error(f"No {target_version} firmware found for {mcu.board} on {mcu.serialport}.")
|
56
|
+
continue
|
57
|
+
if len(board_firmwares) > 1:
|
58
|
+
log.debug(f"Multiple {target_version} firmwares found for {mcu.board} on {mcu.serialport}.")
|
59
|
+
|
60
|
+
# just use the last firmware
|
61
|
+
fw_info = board_firmwares[-1]
|
62
|
+
log.info(f"Found {target_version} firmware {fw_info.filename} for {mcu.board} on {mcu.serialport}.")
|
63
|
+
wl.append((mcu, fw_info))
|
64
|
+
return wl
|
65
|
+
|
66
|
+
|
67
|
+
def manual_worklist(
|
68
|
+
serial: str,
|
69
|
+
*,
|
70
|
+
board_id: str,
|
71
|
+
version: str,
|
72
|
+
fw_folder: Path,
|
73
|
+
) -> WorkList:
|
74
|
+
"""Create a worklist for a single board specified manually.
|
75
|
+
|
76
|
+
Args:
|
77
|
+
serial (str): Serial port of the board
|
78
|
+
board (str): Board_ID
|
79
|
+
version (str): Firmware version
|
80
|
+
fw_folder (Path): Path to the firmware folder
|
81
|
+
|
82
|
+
Returns:
|
83
|
+
WorkList: List of boards and firmware information to update
|
84
|
+
"""
|
85
|
+
log.trace(f"Manual updating {serial} to {board_id} {version}")
|
86
|
+
mcu = MPRemoteBoard(serial)
|
87
|
+
# Lookup the matching port and cpu in board_info based in the board name
|
88
|
+
try:
|
89
|
+
info = find_known_board(board_id)
|
90
|
+
mcu.port = info.port
|
91
|
+
# need the CPU type for the esptool
|
92
|
+
mcu.cpu = info.cpu
|
93
|
+
except (LookupError, MPFlashError) as e:
|
94
|
+
log.error(f"Board {board_id} not found in board_info.zip")
|
95
|
+
log.exception(e)
|
96
|
+
return []
|
97
|
+
mcu.board = board_id
|
98
|
+
firmwares = find_downloaded_firmware(fw_folder=fw_folder, board_id=board_id, version=version, port=mcu.port)
|
99
|
+
if not firmwares:
|
100
|
+
log.error(f"No firmware found for {mcu.port} {board_id} version {version}")
|
101
|
+
return []
|
102
|
+
# use the most recent matching firmware
|
103
|
+
return [(mcu, firmwares[-1])] # type: ignore
|
104
|
+
|
105
|
+
|
106
|
+
def single_auto_worklist(
|
107
|
+
serial: str,
|
108
|
+
*,
|
109
|
+
version: str,
|
110
|
+
fw_folder: Path,
|
111
|
+
) -> WorkList:
|
112
|
+
"""Create a worklist for a single serial-port.
|
113
|
+
|
114
|
+
Args:
|
115
|
+
serial_port (str): Serial port of the board
|
116
|
+
version (str): Firmware version
|
117
|
+
fw_folder (Path): Path to the firmware folder
|
118
|
+
|
119
|
+
Returns:
|
120
|
+
WorkList: List of boards and firmware information to update
|
121
|
+
"""
|
122
|
+
log.trace(f"Auto updating {serial} to {version}")
|
123
|
+
conn_boards = [MPRemoteBoard(serial)]
|
124
|
+
todo = auto_update(conn_boards, version, fw_folder) # type: ignore # List / list
|
125
|
+
show_mcus(conn_boards) # type: ignore
|
126
|
+
return todo
|
127
|
+
|
128
|
+
|
129
|
+
def full_auto_worklist(
|
130
|
+
all_boards: List[MPRemoteBoard], *, include: List[str], ignore: List[str], version: str, fw_folder: Path
|
131
|
+
) -> WorkList:
|
132
|
+
"""
|
133
|
+
Create a worklist for all connected micropython boards based on the information retrieved from the board.
|
134
|
+
This allows the firmware version of one or moae boards to be changed without needing to specify the port or board_id manually.
|
135
|
+
|
136
|
+
Args:
|
137
|
+
version (str): Firmware version
|
138
|
+
fw_folder (Path): Path to the firmware folder
|
139
|
+
|
140
|
+
Returns:
|
141
|
+
WorkList: List of boards and firmware information to update
|
142
|
+
"""
|
143
|
+
log.trace(f"Auto updating all boards to {version}")
|
144
|
+
if selected_boards := filter_boards(all_boards, include=include, ignore=ignore):
|
145
|
+
return auto_update(selected_boards, version, fw_folder)
|
146
|
+
else:
|
147
|
+
return []
|
148
|
+
|
149
|
+
|
150
|
+
def filter_boards(
|
151
|
+
all_boards: List[MPRemoteBoard],
|
152
|
+
*,
|
153
|
+
include: List[str],
|
154
|
+
ignore: List[str],
|
155
|
+
):
|
156
|
+
try:
|
157
|
+
comports = [
|
158
|
+
p.device
|
159
|
+
for p in filtered_comports(
|
160
|
+
ignore=ignore,
|
161
|
+
include=include,
|
162
|
+
bluetooth=False,
|
163
|
+
)
|
164
|
+
]
|
165
|
+
selected_boards = [b for b in all_boards if b.serialport in comports]
|
166
|
+
# [MPRemoteBoard(port.device, update=True) for port in comports]
|
167
|
+
except ConnectionError as e:
|
168
|
+
log.error(f"Error connecting to boards: {e}")
|
169
|
+
return []
|
170
|
+
return selected_boards # type: ignore
|