feat(python): show progress bar for firmware upload

pull/1989/head
matejcik 3 years ago committed by matejcik
parent a2a8cc88d9
commit 83bb3a0932

@ -0,0 +1 @@
`trezorctl firmware update` shows progress bar (Model T only)

@ -394,7 +394,12 @@ def upload_firmware_into_device(
if f.major_version == 1 and f.firmware_present is not False:
# Trezor One does not send ButtonRequest
click.echo("Please confirm the action on your Trezor device")
firmware.update(client, firmware_data)
click.echo("Uploading...\r", nl=False)
with click.progressbar(
label="Uploading", length=len(firmware_data), show_eta=False
) as bar:
firmware.update(client, firmware_data, bar.update)
except exceptions.Cancelled:
click.echo("Update aborted on device.")
except exceptions.TrezorException as e:
@ -582,7 +587,4 @@ def update(
if dry_run:
click.echo("Dry run. Not uploading firmware to device.")
else:
upload_firmware_into_device(
client=client,
firmware_data=firmware_data,
)
upload_firmware_into_device(client=client, firmware_data=firmware_data)

@ -485,7 +485,11 @@ def validate(
@session
def update(client: "TrezorClient", data: bytes) -> None:
def update(
client: "TrezorClient",
data: bytes,
progress_update: Callable[[int], Any] = lambda _: None,
):
if client.features.bootloader_mode is False:
raise RuntimeError("Device must be in bootloader mode")
@ -494,6 +498,7 @@ def update(client: "TrezorClient", data: bytes) -> None:
# TREZORv1 method
if isinstance(resp, messages.Success):
resp = client.call(messages.FirmwareUpload(payload=data))
progress_update(len(data))
if isinstance(resp, messages.Success):
return
else:
@ -503,9 +508,11 @@ def update(client: "TrezorClient", data: bytes) -> None:
while isinstance(resp, messages.FirmwareRequest):
assert resp.offset is not None
assert resp.length is not None
payload = data[resp.offset : resp.offset + resp.length]
length = resp.length
payload = data[resp.offset : resp.offset + length]
digest = blake2s(payload).digest()
resp = client.call(messages.FirmwareUpload(payload=payload, hash=digest))
progress_update(length)
if isinstance(resp, messages.Success):
return

Loading…
Cancel
Save