Skip to content

Commit

Permalink
Merge pull request #36 from tekktrik/dev/fix-nonetype-error
Browse files Browse the repository at this point in the history
Fix board detection for install command
  • Loading branch information
tekktrik authored Feb 23, 2024
2 parents 21857aa + ba42e83 commit fa0cb06
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions circfirm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ def cli() -> None:
@click.option("-b", "--board", default=None, help="Assume the given board name")
def install(version: str, language: str, board: Optional[str]) -> None:
"""Install the specified version of CircuitPython."""
circuitpy = circfirm.backend.find_circuitpy()
bootloader = circfirm.backend.find_bootloader()
if not circuitpy and not bootloader:
click.echo("CircuitPython device not found!")
click.echo("Check that the device is connected and mounted.")
sys.exit(1)

if not board:
circuitpy = circfirm.backend.find_circuitpy()
if not circuitpy and circfirm.backend.find_bootloader():
if not circuitpy and bootloader:
click.echo("CircuitPython device found, but it is in bootloader mode!")
click.echo(
"Please put the device out of bootloader mode, or use the --board option."
Expand All @@ -45,28 +51,22 @@ def install(version: str, language: str, board: Optional[str]) -> None:
board = circfirm.backend.get_board_name(circuitpy)

click.echo("Board name detected, please switch the device to bootloader mode.")
while not circfirm.backend.find_bootloader():
while not (bootloader := circfirm.backend.find_bootloader()):
time.sleep(1)

mount_path = circfirm.backend.find_bootloader()
if not mount_path:
circuitpy = circfirm.backend.find_circuitpy()
if circuitpy:
if not bootloader:
if circfirm.backend.find_circuitpy():
click.echo("CircuitPython device found, but is not in bootloader mode!")
click.echo("Please put the device in bootloader mode.")
sys.exit(2)
else:
click.echo("CircuitPython device not found!")
click.echo("Check that the device is connected and mounted.")
sys.exit(1)

if not circfirm.backend.is_downloaded(board, version, language):
click.echo("Downloading UF2...")
circfirm.backend.download_uf2(board, version, language)

uf2file = circfirm.backend.get_uf2_filepath(board, version, language)
uf2filename = os.path.basename(uf2file)
shutil.copyfile(uf2file, os.path.join(mount_path, uf2filename))
shutil.copyfile(uf2file, os.path.join(bootloader, uf2filename))
click.echo("UF2 file copied to device!")
click.echo("Device should reboot momentarily.")

Expand Down

0 comments on commit fa0cb06

Please sign in to comment.