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/cli_flash.py
CHANGED
@@ -1,216 +1,224 @@
|
|
1
|
-
from pathlib import Path
|
2
|
-
from typing import List
|
3
|
-
|
4
|
-
import rich_click as click
|
5
|
-
from loguru import logger as log
|
6
|
-
|
7
|
-
from mpflash.ask_input import ask_missing_params
|
8
|
-
from mpflash.cli_download import connected_ports_boards
|
9
|
-
from mpflash.cli_group import cli
|
10
|
-
from mpflash.cli_list import show_mcus
|
11
|
-
from mpflash.common import BootloaderMethod, FlashParams, Params
|
12
|
-
from mpflash.config import config
|
13
|
-
from mpflash.errors import MPFlashError
|
14
|
-
from mpflash.flash import flash_list
|
15
|
-
from mpflash.flash.worklist import WorkList, full_auto_worklist, manual_worklist, single_auto_worklist
|
16
|
-
from mpflash.mpboard_id import find_known_board
|
17
|
-
from mpflash.mpremoteboard import MPRemoteBoard
|
18
|
-
from mpflash.versions import clean_version
|
19
|
-
|
20
|
-
# #########################################################################################################
|
21
|
-
# CLI
|
22
|
-
# #########################################################################################################
|
23
|
-
|
24
|
-
|
25
|
-
@cli.command(
|
26
|
-
"flash",
|
27
|
-
short_help="Flash one or all connected MicroPython boards with a specific firmware and version.",
|
28
|
-
)
|
29
|
-
@click.option(
|
30
|
-
"--firmware",
|
31
|
-
"-f",
|
32
|
-
"fw_folder",
|
33
|
-
type=click.Path(file_okay=False, dir_okay=True, path_type=Path),
|
34
|
-
default=config.firmware_folder,
|
35
|
-
show_default=True,
|
36
|
-
help="The folder to retrieve the firmware from.",
|
37
|
-
)
|
38
|
-
@click.option(
|
39
|
-
"--version",
|
40
|
-
"-v",
|
41
|
-
"version", # single version
|
42
|
-
default="stable",
|
43
|
-
multiple=False,
|
44
|
-
show_default=True,
|
45
|
-
help="The version of MicroPython to flash.",
|
46
|
-
metavar="SEMVER, 'stable', 'preview' or '?'",
|
47
|
-
)
|
48
|
-
@click.option(
|
49
|
-
"--serial",
|
50
|
-
"--serial-port",
|
51
|
-
"-s",
|
52
|
-
"serial",
|
53
|
-
default=["*"],
|
54
|
-
multiple=True,
|
55
|
-
show_default=True,
|
56
|
-
help="Which serial port(s) (or globs) to flash",
|
57
|
-
metavar="SERIALPORT",
|
58
|
-
)
|
59
|
-
@click.option(
|
60
|
-
"--ignore",
|
61
|
-
"-i",
|
62
|
-
is_eager=True,
|
63
|
-
help="Serial port(s) to ignore. Defaults to MPFLASH_IGNORE.",
|
64
|
-
multiple=True,
|
65
|
-
default=[],
|
66
|
-
envvar="MPFLASH_IGNORE",
|
67
|
-
show_default=True,
|
68
|
-
metavar="SERIALPORT",
|
69
|
-
)
|
70
|
-
@click.option(
|
71
|
-
"--
|
72
|
-
"-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
"
|
81
|
-
"
|
82
|
-
"
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
)
|
87
|
-
@click.option(
|
88
|
-
"--
|
89
|
-
"
|
90
|
-
"
|
91
|
-
|
92
|
-
help="The
|
93
|
-
metavar="
|
94
|
-
)
|
95
|
-
@click.option(
|
96
|
-
"--
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
"
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
params.
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
)
|
181
|
-
|
182
|
-
#
|
183
|
-
worklist =
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
1
|
+
from pathlib import Path
|
2
|
+
from typing import List
|
3
|
+
|
4
|
+
import rich_click as click
|
5
|
+
from loguru import logger as log
|
6
|
+
|
7
|
+
from mpflash.ask_input import ask_missing_params
|
8
|
+
from mpflash.cli_download import connected_ports_boards
|
9
|
+
from mpflash.cli_group import cli
|
10
|
+
from mpflash.cli_list import show_mcus
|
11
|
+
from mpflash.common import BootloaderMethod, FlashParams, Params
|
12
|
+
from mpflash.config import config
|
13
|
+
from mpflash.errors import MPFlashError
|
14
|
+
from mpflash.flash import flash_list
|
15
|
+
from mpflash.flash.worklist import WorkList, full_auto_worklist, manual_worklist, single_auto_worklist
|
16
|
+
from mpflash.mpboard_id import find_known_board
|
17
|
+
from mpflash.mpremoteboard import MPRemoteBoard
|
18
|
+
from mpflash.versions import clean_version
|
19
|
+
|
20
|
+
# #########################################################################################################
|
21
|
+
# CLI
|
22
|
+
# #########################################################################################################
|
23
|
+
|
24
|
+
|
25
|
+
@cli.command(
|
26
|
+
"flash",
|
27
|
+
short_help="Flash one or all connected MicroPython boards with a specific firmware and version.",
|
28
|
+
)
|
29
|
+
@click.option(
|
30
|
+
"--firmware",
|
31
|
+
"-f",
|
32
|
+
"fw_folder",
|
33
|
+
type=click.Path(file_okay=False, dir_okay=True, path_type=Path),
|
34
|
+
default=config.firmware_folder,
|
35
|
+
show_default=True,
|
36
|
+
help="The folder to retrieve the firmware from.",
|
37
|
+
)
|
38
|
+
@click.option(
|
39
|
+
"--version",
|
40
|
+
"-v",
|
41
|
+
"version", # single version
|
42
|
+
default="stable",
|
43
|
+
multiple=False,
|
44
|
+
show_default=True,
|
45
|
+
help="The version of MicroPython to flash.",
|
46
|
+
metavar="SEMVER, 'stable', 'preview' or '?'",
|
47
|
+
)
|
48
|
+
@click.option(
|
49
|
+
"--serial",
|
50
|
+
"--serial-port",
|
51
|
+
"-s",
|
52
|
+
"serial",
|
53
|
+
default=["*"],
|
54
|
+
multiple=True,
|
55
|
+
show_default=True,
|
56
|
+
help="Which serial port(s) (or globs) to flash",
|
57
|
+
metavar="SERIALPORT",
|
58
|
+
)
|
59
|
+
@click.option(
|
60
|
+
"--ignore",
|
61
|
+
"-i",
|
62
|
+
is_eager=True,
|
63
|
+
help="Serial port(s) to ignore. Defaults to MPFLASH_IGNORE.",
|
64
|
+
multiple=True,
|
65
|
+
default=[],
|
66
|
+
envvar="MPFLASH_IGNORE",
|
67
|
+
show_default=True,
|
68
|
+
metavar="SERIALPORT",
|
69
|
+
)
|
70
|
+
@click.option(
|
71
|
+
"--bluetooth/--no-bluetooth",
|
72
|
+
"-b/-nb",
|
73
|
+
is_flag=True,
|
74
|
+
default=False,
|
75
|
+
show_default=True,
|
76
|
+
help="""Include bluetooth ports in the list""",
|
77
|
+
)
|
78
|
+
@click.option(
|
79
|
+
"--port",
|
80
|
+
"-p",
|
81
|
+
"ports",
|
82
|
+
help="The MicroPython port to flash",
|
83
|
+
metavar="PORT",
|
84
|
+
default=[],
|
85
|
+
multiple=True,
|
86
|
+
)
|
87
|
+
@click.option(
|
88
|
+
"--board",
|
89
|
+
"-b",
|
90
|
+
"board", # single board
|
91
|
+
multiple=False,
|
92
|
+
help="The MicroPython board ID to flash. If not specified will try to read the BOARD_ID from the connected MCU.",
|
93
|
+
metavar="BOARD_ID or ?",
|
94
|
+
)
|
95
|
+
@click.option(
|
96
|
+
"--cpu",
|
97
|
+
"--chip",
|
98
|
+
"-c",
|
99
|
+
"cpu",
|
100
|
+
help="The CPU type to flash. If not specified will try to read the CPU from the connected MCU.",
|
101
|
+
metavar="CPU",
|
102
|
+
)
|
103
|
+
@click.option(
|
104
|
+
"--erase/--no-erase",
|
105
|
+
default=True,
|
106
|
+
show_default=True,
|
107
|
+
help="""Erase flash before writing new firmware. (Not supported on UF2 boards)""",
|
108
|
+
)
|
109
|
+
@click.option(
|
110
|
+
"--bootloader",
|
111
|
+
"-bl",
|
112
|
+
"bootloader",
|
113
|
+
type=click.Choice([e.value for e in BootloaderMethod]),
|
114
|
+
default="auto",
|
115
|
+
show_default=True,
|
116
|
+
help="""How to enter the (MicroPython) bootloader before flashing.""",
|
117
|
+
)
|
118
|
+
def cli_flash_board(**kwargs) -> int:
|
119
|
+
# version to versions, board to boards
|
120
|
+
kwargs["versions"] = [kwargs.pop("version")] if kwargs["version"] != None else []
|
121
|
+
if kwargs["board"] is None:
|
122
|
+
kwargs["boards"] = []
|
123
|
+
kwargs.pop("board")
|
124
|
+
else:
|
125
|
+
kwargs["boards"] = [kwargs.pop("board")]
|
126
|
+
|
127
|
+
params = FlashParams(**kwargs)
|
128
|
+
params.versions = list(params.versions)
|
129
|
+
params.ports = list(params.ports)
|
130
|
+
params.boards = list(params.boards)
|
131
|
+
params.serial = list(params.serial)
|
132
|
+
params.ignore = list(params.ignore)
|
133
|
+
params.bootloader = BootloaderMethod(params.bootloader)
|
134
|
+
|
135
|
+
# make it simple for the user to flash one board by asking for the serial port if not specified
|
136
|
+
if params.boards == ["?"] and params.serial == "*":
|
137
|
+
params.serial = ["?"]
|
138
|
+
|
139
|
+
# Detect connected boards if not specified,
|
140
|
+
# and ask for input if boards cannot be detected
|
141
|
+
all_boards: List[MPRemoteBoard] = []
|
142
|
+
if not params.boards:
|
143
|
+
# nothing specified - detect connected boards
|
144
|
+
params.ports, params.boards, all_boards = connected_ports_boards(include=params.ports, ignore=params.ignore, bluetooth=params.bluetooth)
|
145
|
+
if params.boards == []:
|
146
|
+
# No MicroPython boards detected, but it could be unflashed or in bootloader mode
|
147
|
+
# Ask for serial port and board_id to flash
|
148
|
+
params.serial = ["?"]
|
149
|
+
params.boards = ["?"]
|
150
|
+
# assume manual mode if no board is detected
|
151
|
+
params.bootloader = BootloaderMethod("manual")
|
152
|
+
else:
|
153
|
+
resolve_board_ids(params)
|
154
|
+
|
155
|
+
# Ask for missing input if needed
|
156
|
+
params = ask_missing_params(params)
|
157
|
+
if not params: # Cancelled by user
|
158
|
+
return 2
|
159
|
+
# TODO: Just in time Download of firmware
|
160
|
+
|
161
|
+
assert isinstance(params, FlashParams)
|
162
|
+
|
163
|
+
if len(params.versions) > 1:
|
164
|
+
log.error(f"Only one version can be flashed at a time, not {params.versions}")
|
165
|
+
raise MPFlashError("Only one version can be flashed at a time")
|
166
|
+
|
167
|
+
params.versions = [clean_version(v) for v in params.versions]
|
168
|
+
worklist: WorkList = []
|
169
|
+
# if serial port == auto and there are one or more specified/detected boards
|
170
|
+
if params.serial == ["*"] and params.boards:
|
171
|
+
if not all_boards:
|
172
|
+
log.trace("No boards detected yet, scanning for connected boards")
|
173
|
+
_, _, all_boards = connected_ports_boards(include=params.ports, ignore=params.ignore)
|
174
|
+
worklist = full_auto_worklist(
|
175
|
+
all_boards=all_boards,
|
176
|
+
version=params.versions[0],
|
177
|
+
fw_folder=params.fw_folder,
|
178
|
+
include=params.serial,
|
179
|
+
ignore=params.ignore,
|
180
|
+
)
|
181
|
+
elif params.versions[0] and params.boards[0] and params.serial:
|
182
|
+
# A one or more serial port including the board / variant
|
183
|
+
worklist = manual_worklist(
|
184
|
+
params.serial[0],
|
185
|
+
board_id=params.boards[0],
|
186
|
+
version=params.versions[0],
|
187
|
+
fw_folder=params.fw_folder,
|
188
|
+
)
|
189
|
+
else:
|
190
|
+
# just this serial port on auto
|
191
|
+
worklist = single_auto_worklist(
|
192
|
+
serial=params.serial[0],
|
193
|
+
version=params.versions[0],
|
194
|
+
fw_folder=params.fw_folder,
|
195
|
+
)
|
196
|
+
|
197
|
+
if flashed := flash_list(
|
198
|
+
worklist,
|
199
|
+
params.fw_folder,
|
200
|
+
params.erase,
|
201
|
+
params.bootloader,
|
202
|
+
):
|
203
|
+
log.info(f"Flashed {len(flashed)} boards")
|
204
|
+
show_mcus(flashed, title="Updated boards after flashing")
|
205
|
+
return 0
|
206
|
+
else:
|
207
|
+
log.error("No boards were flashed")
|
208
|
+
return 1
|
209
|
+
|
210
|
+
|
211
|
+
def resolve_board_ids(params: Params):
|
212
|
+
"""Resolve board descriptions to board_id, and remove empty strings from list of boards"""
|
213
|
+
for board_id in params.boards:
|
214
|
+
if board_id == "":
|
215
|
+
params.boards.remove(board_id)
|
216
|
+
continue
|
217
|
+
if " " in board_id:
|
218
|
+
try:
|
219
|
+
if info := find_known_board(board_id):
|
220
|
+
log.info(f"Resolved board description: {info.board_id}")
|
221
|
+
params.boards.remove(board_id)
|
222
|
+
params.boards.append(info.board_id)
|
223
|
+
except Exception as e:
|
224
|
+
log.warning(f"Unable to resolve board description: {e}")
|
mpflash/cli_group.py
CHANGED
@@ -1,111 +1,111 @@
|
|
1
|
-
"""
|
2
|
-
Main entry point for the CLI group.
|
3
|
-
Additional comands are added in the submodules.
|
4
|
-
"""
|
5
|
-
|
6
|
-
import rich_click as click
|
7
|
-
|
8
|
-
from mpflash.vendor.click_aliases import ClickAliasedGroup
|
9
|
-
|
10
|
-
from .config import __version__, config
|
11
|
-
from .logger import log, make_quiet, set_loglevel
|
12
|
-
|
13
|
-
|
14
|
-
def cb_verbose(ctx, param, value):
|
15
|
-
"""Callback to set the log level to DEBUG if verbose is set"""
|
16
|
-
if value and not config.quiet:
|
17
|
-
# log.debug(f"Setting verbose mode to {value}")
|
18
|
-
config.verbose = True
|
19
|
-
if value > 1:
|
20
|
-
set_loglevel("TRACE")
|
21
|
-
else:
|
22
|
-
set_loglevel("DEBUG")
|
23
|
-
log.debug(f"version: {__version__}")
|
24
|
-
else:
|
25
|
-
set_loglevel("INFO")
|
26
|
-
config.verbose = False
|
27
|
-
return value
|
28
|
-
|
29
|
-
|
30
|
-
def cb_interactive(ctx, param, value: bool):
|
31
|
-
log.trace(f"Setting interactive mode to {value}")
|
32
|
-
config.interactive = value
|
33
|
-
return value
|
34
|
-
|
35
|
-
|
36
|
-
def cb_test(ctx, param, value):
|
37
|
-
if value:
|
38
|
-
log.trace(f"Setting tests to {value}")
|
39
|
-
config.tests = value
|
40
|
-
return value
|
41
|
-
|
42
|
-
def cb_usb(ctx, param, value: bool):
|
43
|
-
config.usb = bool(value)
|
44
|
-
return value
|
45
|
-
|
46
|
-
|
47
|
-
def cb_quiet(ctx, param, value):
|
48
|
-
log.trace(f"Setting quiet mode to {value}")
|
49
|
-
if value:
|
50
|
-
make_quiet()
|
51
|
-
return value
|
52
|
-
|
53
|
-
|
54
|
-
@click.group(cls=ClickAliasedGroup)
|
55
|
-
# @click.group()
|
56
|
-
@click.version_option(package_name="mpflash")
|
57
|
-
@click.option(
|
58
|
-
"--quiet",
|
59
|
-
"-q",
|
60
|
-
is_eager=True,
|
61
|
-
is_flag=True,
|
62
|
-
help="Suppresses all output.",
|
63
|
-
callback=cb_quiet,
|
64
|
-
envvar="MPFLASH_QUIET",
|
65
|
-
show_default=True,
|
66
|
-
)
|
67
|
-
@click.option(
|
68
|
-
"--interactive/--no-interactive",
|
69
|
-
"-i/-x",
|
70
|
-
is_eager=True,
|
71
|
-
help="Suppresses all request for Input.",
|
72
|
-
callback=cb_interactive,
|
73
|
-
# envvar="MPFLASH_QUIET",
|
74
|
-
default=True,
|
75
|
-
show_default=True,
|
76
|
-
)
|
77
|
-
@click.option(
|
78
|
-
"-V",
|
79
|
-
"--verbose",
|
80
|
-
is_eager=True,
|
81
|
-
count=True,
|
82
|
-
help="Enables verbose mode.",
|
83
|
-
callback=cb_verbose,
|
84
|
-
)
|
85
|
-
@click.option(
|
86
|
-
"--usb",
|
87
|
-
"-u",
|
88
|
-
is_eager=True,
|
89
|
-
is_flag=True,
|
90
|
-
default=False,
|
91
|
-
help="Shows USB location of the connected boards.",
|
92
|
-
callback=cb_usb,
|
93
|
-
show_default=True,
|
94
|
-
)
|
95
|
-
@click.option(
|
96
|
-
"--test",
|
97
|
-
is_eager=True,
|
98
|
-
help="Test a specific feature.",
|
99
|
-
callback=cb_test,
|
100
|
-
multiple=True,
|
101
|
-
default=[],
|
102
|
-
envvar="MPFLASH_TEST",
|
103
|
-
metavar="FLAG",
|
104
|
-
)
|
105
|
-
def cli(**kwargs):
|
106
|
-
"""mpflash - MicroPython flashing tool.
|
107
|
-
|
108
|
-
A CLI to download and flash MicroPython firmware to different ports and boards.
|
109
|
-
"""
|
110
|
-
# all functionality is added in the submodules
|
111
|
-
pass
|
1
|
+
"""
|
2
|
+
Main entry point for the CLI group.
|
3
|
+
Additional comands are added in the submodules.
|
4
|
+
"""
|
5
|
+
|
6
|
+
import rich_click as click
|
7
|
+
|
8
|
+
from mpflash.vendor.click_aliases import ClickAliasedGroup
|
9
|
+
|
10
|
+
from .config import __version__, config
|
11
|
+
from .logger import log, make_quiet, set_loglevel
|
12
|
+
|
13
|
+
|
14
|
+
def cb_verbose(ctx, param, value):
|
15
|
+
"""Callback to set the log level to DEBUG if verbose is set"""
|
16
|
+
if value and not config.quiet:
|
17
|
+
# log.debug(f"Setting verbose mode to {value}")
|
18
|
+
config.verbose = True
|
19
|
+
if value > 1:
|
20
|
+
set_loglevel("TRACE")
|
21
|
+
else:
|
22
|
+
set_loglevel("DEBUG")
|
23
|
+
log.debug(f"version: {__version__}")
|
24
|
+
else:
|
25
|
+
set_loglevel("INFO")
|
26
|
+
config.verbose = False
|
27
|
+
return value
|
28
|
+
|
29
|
+
|
30
|
+
def cb_interactive(ctx, param, value: bool):
|
31
|
+
log.trace(f"Setting interactive mode to {value}")
|
32
|
+
config.interactive = value
|
33
|
+
return value
|
34
|
+
|
35
|
+
|
36
|
+
def cb_test(ctx, param, value):
|
37
|
+
if value:
|
38
|
+
log.trace(f"Setting tests to {value}")
|
39
|
+
config.tests = value
|
40
|
+
return value
|
41
|
+
|
42
|
+
def cb_usb(ctx, param, value: bool):
|
43
|
+
config.usb = bool(value)
|
44
|
+
return value
|
45
|
+
|
46
|
+
|
47
|
+
def cb_quiet(ctx, param, value):
|
48
|
+
log.trace(f"Setting quiet mode to {value}")
|
49
|
+
if value:
|
50
|
+
make_quiet()
|
51
|
+
return value
|
52
|
+
|
53
|
+
|
54
|
+
@click.group(cls=ClickAliasedGroup)
|
55
|
+
# @click.group()
|
56
|
+
@click.version_option(package_name="mpflash")
|
57
|
+
@click.option(
|
58
|
+
"--quiet",
|
59
|
+
"-q",
|
60
|
+
is_eager=True,
|
61
|
+
is_flag=True,
|
62
|
+
help="Suppresses all output.",
|
63
|
+
callback=cb_quiet,
|
64
|
+
envvar="MPFLASH_QUIET",
|
65
|
+
show_default=True,
|
66
|
+
)
|
67
|
+
@click.option(
|
68
|
+
"--interactive/--no-interactive",
|
69
|
+
"-i/-x",
|
70
|
+
is_eager=True,
|
71
|
+
help="Suppresses all request for Input.",
|
72
|
+
callback=cb_interactive,
|
73
|
+
# envvar="MPFLASH_QUIET",
|
74
|
+
default=True,
|
75
|
+
show_default=True,
|
76
|
+
)
|
77
|
+
@click.option(
|
78
|
+
"-V",
|
79
|
+
"--verbose",
|
80
|
+
is_eager=True,
|
81
|
+
count=True,
|
82
|
+
help="Enables verbose mode.",
|
83
|
+
callback=cb_verbose,
|
84
|
+
)
|
85
|
+
@click.option(
|
86
|
+
"--usb",
|
87
|
+
"-u",
|
88
|
+
is_eager=True,
|
89
|
+
is_flag=True,
|
90
|
+
default=False,
|
91
|
+
help="Shows USB location of the connected boards.",
|
92
|
+
callback=cb_usb,
|
93
|
+
show_default=True,
|
94
|
+
)
|
95
|
+
@click.option(
|
96
|
+
"--test",
|
97
|
+
is_eager=True,
|
98
|
+
help="Test a specific feature.",
|
99
|
+
callback=cb_test,
|
100
|
+
multiple=True,
|
101
|
+
default=[],
|
102
|
+
envvar="MPFLASH_TEST",
|
103
|
+
metavar="FLAG",
|
104
|
+
)
|
105
|
+
def cli(**kwargs):
|
106
|
+
"""mpflash - MicroPython flashing tool.
|
107
|
+
|
108
|
+
A CLI to download and flash MicroPython firmware to different ports and boards.
|
109
|
+
"""
|
110
|
+
# all functionality is added in the submodules
|
111
|
+
pass
|