Skip to content

Commit 0142fb1

Browse files
committed
cli.flash: finish removal of REPLHub
Remove REPLHub from the flash command. REPLHub was removed in commit 8b44f69 ("pybricksdev/connections: Drop REPLHub.") so it was causing an import error. Fixes: #117
1 parent 9b84ee4 commit 0142fb1

File tree

1 file changed

+1
-40
lines changed

1 file changed

+1
-40
lines changed

pybricksdev/cli/flash.py

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
# Copyright (c) 2019-2023 The Pybricks Authors
33

44
import asyncio
5-
import hashlib
6-
import json
75
import logging
86
import os
97
import struct
108
import sys
11-
import zipfile
129
import zlib
1310
from tempfile import NamedTemporaryFile
1411
from typing import BinaryIO, Dict, Optional
@@ -46,7 +43,6 @@
4643
unpack_pnp_id,
4744
)
4845
from pybricksdev.compile import compile_file
49-
from pybricksdev.connections.lego import REPLHub
5046
from pybricksdev.dfu import flash_dfu
5147
from pybricksdev.firmware import create_firmware_blob
5248
from pybricksdev.flash import BootloaderConnection
@@ -439,42 +435,7 @@ async def flash_firmware(firmware_zip: BinaryIO, new_name: Optional[str]) -> Non
439435
hub_kind = HubKind(metadata["device-id"])
440436

441437
if hub_kind in (HubKind.TECHNIC_SMALL, HubKind.TECHNIC_LARGE):
442-
try:
443-
# Connect to the hub and exit the runtime.
444-
hub = REPLHub()
445-
await hub.connect()
446-
await hub.reset_hub()
447-
448-
# Upload installation script.
449-
archive = zipfile.ZipFile(firmware_zip)
450-
await hub.exec_line("import uos; uos.mkdir('_firmware')")
451-
await hub.upload_file(
452-
"_firmware/install_pybricks.py",
453-
bytearray(archive.open("install_pybricks.py").read()),
454-
)
455-
456-
extended_metadata = metadata.copy()
457-
458-
# Add extended metadata needed by install_pybricks.py
459-
extended_metadata["firmware-sha256"] = hashlib.sha256(firmware).hexdigest()
460-
461-
# Upload metadata.
462-
await hub.upload_file(
463-
"_firmware/firmware.metadata.json",
464-
json.dumps(extended_metadata, indent=4).encode(),
465-
)
466-
467-
# Upload Pybricks firmware
468-
await hub.upload_file("_firmware/firmware.bin", firmware)
469-
470-
# Run installation script
471-
print("Installing firmware")
472-
await hub.exec_line("from _firmware.install_pybricks import install")
473-
await hub.exec_paste_mode("install()")
474-
475-
except OSError:
476-
print("Could not find hub in standard firmware mode. Trying DFU.")
477-
flash_dfu(firmware, metadata)
438+
flash_dfu(firmware, metadata)
478439
elif hub_kind in [HubKind.BOOST, HubKind.CITY, HubKind.TECHNIC]:
479440
await flash_ble(hub_kind, firmware, metadata)
480441
elif hub_kind == HubKind.NXT:

0 commit comments

Comments
 (0)