mpflash 1.0.0__py3-none-any.whl → 1.0.2__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.
- mpflash/add_firmware.py +98 -98
- mpflash/ask_input.py +236 -236
- mpflash/basicgit.py +284 -284
- mpflash/bootloader/__init__.py +2 -2
- mpflash/bootloader/activate.py +60 -60
- mpflash/bootloader/detect.py +82 -82
- mpflash/bootloader/manual.py +101 -101
- mpflash/bootloader/micropython.py +12 -12
- mpflash/bootloader/touch1200.py +36 -36
- mpflash/cli_download.py +129 -129
- mpflash/cli_flash.py +224 -216
- mpflash/cli_group.py +111 -111
- mpflash/cli_list.py +87 -87
- mpflash/cli_main.py +39 -39
- mpflash/common.py +210 -166
- mpflash/config.py +44 -44
- mpflash/connected.py +104 -77
- mpflash/download.py +364 -364
- mpflash/downloaded.py +130 -130
- mpflash/errors.py +9 -9
- mpflash/flash/__init__.py +55 -55
- mpflash/flash/esp.py +59 -59
- mpflash/flash/stm32.py +19 -19
- mpflash/flash/stm32_dfu.py +104 -104
- mpflash/flash/uf2/__init__.py +88 -88
- mpflash/flash/uf2/boardid.py +15 -15
- mpflash/flash/uf2/linux.py +136 -130
- mpflash/flash/uf2/macos.py +42 -42
- mpflash/flash/uf2/uf2disk.py +12 -12
- mpflash/flash/uf2/windows.py +43 -43
- mpflash/flash/worklist.py +170 -170
- mpflash/list.py +106 -106
- mpflash/logger.py +41 -41
- mpflash/mpboard_id/__init__.py +93 -93
- mpflash/mpboard_id/add_boards.py +251 -251
- mpflash/mpboard_id/board.py +37 -37
- mpflash/mpboard_id/board_id.py +86 -86
- mpflash/mpboard_id/store.py +43 -43
- mpflash/mpremoteboard/__init__.py +266 -266
- mpflash/mpremoteboard/mpy_fw_info.py +141 -141
- mpflash/mpremoteboard/runner.py +140 -140
- mpflash/vendor/click_aliases.py +91 -91
- mpflash/vendor/dfu.py +165 -165
- mpflash/vendor/pydfu.py +605 -605
- mpflash/vendor/readme.md +2 -2
- mpflash/versions.py +135 -135
- {mpflash-1.0.0.dist-info → mpflash-1.0.2.dist-info}/LICENSE +20 -20
- {mpflash-1.0.0.dist-info → mpflash-1.0.2.dist-info}/METADATA +1 -1
- mpflash-1.0.2.dist-info/RECORD +53 -0
- mpflash-1.0.0.dist-info/RECORD +0 -53
- {mpflash-1.0.0.dist-info → mpflash-1.0.2.dist-info}/WHEEL +0 -0
- {mpflash-1.0.0.dist-info → mpflash-1.0.2.dist-info}/entry_points.txt +0 -0
mpflash/mpboard_id/board_id.py
CHANGED
@@ -1,86 +1,86 @@
|
|
1
|
-
"""
|
2
|
-
Translate board description to board designator
|
3
|
-
"""
|
4
|
-
|
5
|
-
import functools
|
6
|
-
from pathlib import Path
|
7
|
-
from typing import Optional
|
8
|
-
|
9
|
-
from mpflash.errors import MPFlashError
|
10
|
-
from mpflash.logger import log
|
11
|
-
from mpflash.mpboard_id.store import read_known_boardinfo
|
12
|
-
from mpflash.versions import clean_version, get_stable_mp_version
|
13
|
-
|
14
|
-
|
15
|
-
def find_board_id_by_description(
|
16
|
-
descr: str,
|
17
|
-
short_descr: str,
|
18
|
-
*,
|
19
|
-
version: str,
|
20
|
-
board_info: Optional[Path] = None,
|
21
|
-
) -> Optional[str]:
|
22
|
-
"""Find the MicroPython BOARD_ID based on the description in the firmware"""
|
23
|
-
|
24
|
-
try:
|
25
|
-
boards = _find_board_id_by_description(
|
26
|
-
descr=descr,
|
27
|
-
short_descr=short_descr,
|
28
|
-
board_info=board_info,
|
29
|
-
version=clean_version(version) if version else None,
|
30
|
-
)
|
31
|
-
return boards[-1].board_id
|
32
|
-
except MPFlashError:
|
33
|
-
return "UNKNOWN_BOARD"
|
34
|
-
|
35
|
-
|
36
|
-
@functools.lru_cache(maxsize=20)
|
37
|
-
def _find_board_id_by_description(
|
38
|
-
*,
|
39
|
-
descr: str,
|
40
|
-
short_descr: str,
|
41
|
-
version: Optional[str] = None,
|
42
|
-
board_info: Optional[Path] = None,
|
43
|
-
):
|
44
|
-
"""
|
45
|
-
Find the MicroPython BOARD_ID based on the description in the firmware
|
46
|
-
using the pre-built board_info.json file
|
47
|
-
|
48
|
-
Parameters:
|
49
|
-
descr: str
|
50
|
-
Description of the board
|
51
|
-
short_descr: str
|
52
|
-
Short description of the board (optional)
|
53
|
-
version: str
|
54
|
-
Version of the MicroPython firmware
|
55
|
-
board_info: Path
|
56
|
-
Path to the board_info.json file (optional)
|
57
|
-
|
58
|
-
"""
|
59
|
-
# FIXME: functional overlap with
|
60
|
-
# src\mpflash\mpflash\mpboard_id\__init__.py find_known_board
|
61
|
-
|
62
|
-
if not short_descr and " with " in descr:
|
63
|
-
short_descr = descr.split(" with ")[0]
|
64
|
-
|
65
|
-
candidate_boards = read_known_boardinfo(board_info)
|
66
|
-
|
67
|
-
if version:
|
68
|
-
# filter for matching version
|
69
|
-
if version in ("preview", "stable"):
|
70
|
-
# match last stable
|
71
|
-
version = get_stable_mp_version()
|
72
|
-
known_versions = sorted({b.version for b in candidate_boards})
|
73
|
-
if version not in known_versions:
|
74
|
-
# FIXME if latest stable is newer than the last version in the boardlist this will fail
|
75
|
-
log.trace(f"Version {version} not found in board info, using latest known version {known_versions[-1]}")
|
76
|
-
version = known_versions[-1]
|
77
|
-
if version_matches := [b for b in candidate_boards if b.version.startswith(version)]:
|
78
|
-
candidate_boards = version_matches
|
79
|
-
else:
|
80
|
-
raise MPFlashError(f"No board info found for version {version}")
|
81
|
-
matches = [b for b in candidate_boards if b.description == descr]
|
82
|
-
if not matches and short_descr:
|
83
|
-
matches = [b for b in candidate_boards if b.description == short_descr]
|
84
|
-
if not matches:
|
85
|
-
raise MPFlashError(f"No board info found for description '{descr}' or '{short_descr}'")
|
86
|
-
return sorted(matches, key=lambda x: x.version)
|
1
|
+
"""
|
2
|
+
Translate board description to board designator
|
3
|
+
"""
|
4
|
+
|
5
|
+
import functools
|
6
|
+
from pathlib import Path
|
7
|
+
from typing import Optional
|
8
|
+
|
9
|
+
from mpflash.errors import MPFlashError
|
10
|
+
from mpflash.logger import log
|
11
|
+
from mpflash.mpboard_id.store import read_known_boardinfo
|
12
|
+
from mpflash.versions import clean_version, get_stable_mp_version
|
13
|
+
|
14
|
+
|
15
|
+
def find_board_id_by_description(
|
16
|
+
descr: str,
|
17
|
+
short_descr: str,
|
18
|
+
*,
|
19
|
+
version: str,
|
20
|
+
board_info: Optional[Path] = None,
|
21
|
+
) -> Optional[str]:
|
22
|
+
"""Find the MicroPython BOARD_ID based on the description in the firmware"""
|
23
|
+
|
24
|
+
try:
|
25
|
+
boards = _find_board_id_by_description(
|
26
|
+
descr=descr,
|
27
|
+
short_descr=short_descr,
|
28
|
+
board_info=board_info,
|
29
|
+
version=clean_version(version) if version else None,
|
30
|
+
)
|
31
|
+
return boards[-1].board_id
|
32
|
+
except MPFlashError:
|
33
|
+
return "UNKNOWN_BOARD"
|
34
|
+
|
35
|
+
|
36
|
+
@functools.lru_cache(maxsize=20)
|
37
|
+
def _find_board_id_by_description(
|
38
|
+
*,
|
39
|
+
descr: str,
|
40
|
+
short_descr: str,
|
41
|
+
version: Optional[str] = None,
|
42
|
+
board_info: Optional[Path] = None,
|
43
|
+
):
|
44
|
+
"""
|
45
|
+
Find the MicroPython BOARD_ID based on the description in the firmware
|
46
|
+
using the pre-built board_info.json file
|
47
|
+
|
48
|
+
Parameters:
|
49
|
+
descr: str
|
50
|
+
Description of the board
|
51
|
+
short_descr: str
|
52
|
+
Short description of the board (optional)
|
53
|
+
version: str
|
54
|
+
Version of the MicroPython firmware
|
55
|
+
board_info: Path
|
56
|
+
Path to the board_info.json file (optional)
|
57
|
+
|
58
|
+
"""
|
59
|
+
# FIXME: functional overlap with
|
60
|
+
# src\mpflash\mpflash\mpboard_id\__init__.py find_known_board
|
61
|
+
|
62
|
+
if not short_descr and " with " in descr:
|
63
|
+
short_descr = descr.split(" with ")[0]
|
64
|
+
|
65
|
+
candidate_boards = read_known_boardinfo(board_info)
|
66
|
+
|
67
|
+
if version:
|
68
|
+
# filter for matching version
|
69
|
+
if version in ("preview", "stable"):
|
70
|
+
# match last stable
|
71
|
+
version = get_stable_mp_version()
|
72
|
+
known_versions = sorted({b.version for b in candidate_boards})
|
73
|
+
if version not in known_versions:
|
74
|
+
# FIXME if latest stable is newer than the last version in the boardlist this will fail
|
75
|
+
log.trace(f"Version {version} not found in board info, using latest known version {known_versions[-1]}")
|
76
|
+
version = known_versions[-1]
|
77
|
+
if version_matches := [b for b in candidate_boards if b.version.startswith(version)]:
|
78
|
+
candidate_boards = version_matches
|
79
|
+
else:
|
80
|
+
raise MPFlashError(f"No board info found for version {version}")
|
81
|
+
matches = [b for b in candidate_boards if b.description == descr]
|
82
|
+
if not matches and short_descr:
|
83
|
+
matches = [b for b in candidate_boards if b.description == short_descr]
|
84
|
+
if not matches:
|
85
|
+
raise MPFlashError(f"No board info found for description '{descr}' or '{short_descr}'")
|
86
|
+
return sorted(matches, key=lambda x: x.version)
|
mpflash/mpboard_id/store.py
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
import functools
|
2
|
-
import zipfile
|
3
|
-
from pathlib import Path
|
4
|
-
from typing import List, Optional
|
5
|
-
|
6
|
-
import jsons
|
7
|
-
|
8
|
-
from mpflash.mpboard_id.board import Board
|
9
|
-
|
10
|
-
###############################################################################################
|
11
|
-
HERE = Path(__file__).parent
|
12
|
-
###############################################################################################
|
13
|
-
|
14
|
-
|
15
|
-
def write_boardinfo_json(board_list: List[Board], *, folder: Path):
|
16
|
-
"""Writes the board information to a JSON file.
|
17
|
-
|
18
|
-
Args:
|
19
|
-
board_list (List[Board]): The list of Board objects.
|
20
|
-
folder (Path): The folder where the compressed JSON file will be saved.
|
21
|
-
"""
|
22
|
-
import zipfile
|
23
|
-
|
24
|
-
# create a zip file with the json file
|
25
|
-
with zipfile.ZipFile(folder / "board_info.zip", "w", compression=zipfile.ZIP_DEFLATED) as zipf:
|
26
|
-
# write the list to json file inside the zip
|
27
|
-
with zipf.open("board_info.json", "w") as fp:
|
28
|
-
fp.write(jsons.dumps(board_list, jdkwargs={"indent": 4}).encode())
|
29
|
-
|
30
|
-
|
31
|
-
@functools.lru_cache(maxsize=20)
|
32
|
-
def read_known_boardinfo(board_info: Optional[Path] = None) -> List[Board]:
|
33
|
-
|
34
|
-
if not board_info:
|
35
|
-
board_info = HERE / "board_info.zip"
|
36
|
-
if not board_info.exists():
|
37
|
-
raise FileNotFoundError(f"Board info file not found: {board_info}")
|
38
|
-
|
39
|
-
with zipfile.ZipFile(board_info, "r") as zf:
|
40
|
-
with zf.open("board_info.json", "r") as file:
|
41
|
-
info = jsons.loads(file.read().decode(encoding="utf-8"), List[Board])
|
42
|
-
|
43
|
-
return info
|
1
|
+
import functools
|
2
|
+
import zipfile
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import List, Optional
|
5
|
+
|
6
|
+
import jsons
|
7
|
+
|
8
|
+
from mpflash.mpboard_id.board import Board
|
9
|
+
|
10
|
+
###############################################################################################
|
11
|
+
HERE = Path(__file__).parent
|
12
|
+
###############################################################################################
|
13
|
+
|
14
|
+
|
15
|
+
def write_boardinfo_json(board_list: List[Board], *, folder: Path):
|
16
|
+
"""Writes the board information to a JSON file.
|
17
|
+
|
18
|
+
Args:
|
19
|
+
board_list (List[Board]): The list of Board objects.
|
20
|
+
folder (Path): The folder where the compressed JSON file will be saved.
|
21
|
+
"""
|
22
|
+
import zipfile
|
23
|
+
|
24
|
+
# create a zip file with the json file
|
25
|
+
with zipfile.ZipFile(folder / "board_info.zip", "w", compression=zipfile.ZIP_DEFLATED) as zipf:
|
26
|
+
# write the list to json file inside the zip
|
27
|
+
with zipf.open("board_info.json", "w") as fp:
|
28
|
+
fp.write(jsons.dumps(board_list, jdkwargs={"indent": 4}).encode())
|
29
|
+
|
30
|
+
|
31
|
+
@functools.lru_cache(maxsize=20)
|
32
|
+
def read_known_boardinfo(board_info: Optional[Path] = None) -> List[Board]:
|
33
|
+
|
34
|
+
if not board_info:
|
35
|
+
board_info = HERE / "board_info.zip"
|
36
|
+
if not board_info.exists():
|
37
|
+
raise FileNotFoundError(f"Board info file not found: {board_info}")
|
38
|
+
|
39
|
+
with zipfile.ZipFile(board_info, "r") as zf:
|
40
|
+
with zf.open("board_info.json", "r") as file:
|
41
|
+
info = jsons.loads(file.read().decode(encoding="utf-8"), List[Board])
|
42
|
+
|
43
|
+
return info
|