Skip to content

Commit

Permalink
Merge pull request #18 from tekktrik/dev/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
tekktrik authored Feb 21, 2024
2 parents 7a7ade6 + e400809 commit 9859a82
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 18 deletions.
6 changes: 5 additions & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Upstream-Contact: Alec Delaney <[email protected]>
Source: https://github.com/tekktrik/cronberry

Files: tests/assets/info_uf2.txt
Copyright: 2024 Alec Delaney, for Adafruit Industries
Copyright: 2024 Scott Shawcroft, for Adafruit Industries
License: MIT

Files: tests/assets/boot_out.txt
Copyright: 2024 Scott Shawcroft, for Adafruit Industries
License: MIT

Files: tests/assets/firmwares/*.uf2
Expand Down
2 changes: 0 additions & 2 deletions circfirm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

from circfirm.startup import setup_app_dir, setup_file, setup_folder

__version__ = "0.0.0+auto.0"

# Folders

APP_DIR = setup_app_dir("circfirm")
Expand Down
26 changes: 16 additions & 10 deletions circfirm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,28 @@


@click.group()
@click.version_option(circfirm.__version__)
@click.version_option(package_name="circfirm")
def cli() -> None:
"""Install CircuitPython firmware from the command line."""
circfirm.startup.ensure_app_setup()


@cli.command()
@click.argument("version")
@click.option("-l", "--language", default="en_US")
@click.option("-l", "--language", default="en_US", help="CircuitPython language/locale")
def install(version: str, language: str) -> None:
"""Install the specified version of CircuitPython."""
mount_path = circfirm.backend.find_bootloader()
if not mount_path:
click.echo("CircuitPython device not found!")
click.echo("Check that the device is connected and mounted.")
sys.exit(1)
circuitpy = circfirm.backend.find_circuitpy()
if 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)

board = circfirm.backend.get_board_name(mount_path)

Expand All @@ -58,9 +64,9 @@ def cache():


@cache.command()
@click.option("-b", "--board", default=None)
@click.option("-v", "--version", default=None)
@click.option("-l", "--language", default=None)
@click.option("-b", "--board", default=None, help="CircuitPythonoard name")
@click.option("-v", "--version", default=None, help="CircuitPython version")
@click.option("-l", "--language", default=None, help="CircuitPython language/locale")
def clear(
board: Optional[str], version: Optional[str], language: Optional[str]
) -> None:
Expand Down Expand Up @@ -91,7 +97,7 @@ def clear(


@cache.command(name="list")
@click.option("-b", "--board", default=None)
@click.option("-b", "--board", default=None, help="CircuitPython board name")
def cache_list(board: Optional[str]) -> None:
"""List all the boards/versions cached."""
if board is not None:
Expand Down Expand Up @@ -119,7 +125,7 @@ def cache_list(board: Optional[str]) -> None:
@cache.command(name="save")
@click.argument("board")
@click.argument("version")
@click.option("-l", "--language", default="en_US")
@click.option("-l", "--language", default="en_US", help="CircuitPython language/locale")
def cache_save(board: str, version: str, language: str) -> None:
"""Install a version of CircuitPython to cache."""
try:
Expand Down
3 changes: 3 additions & 0 deletions tests/assets/boot_out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Adafruit CircuitPython 8.2.9 on 2023-12-06; Adafruit Feather STM32F405 Express with STM32F405RG
Board ID:feather_stm32f405_express
UID:250026001050304235343220
18 changes: 14 additions & 4 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_mount() -> str:
"""Get the mounted drive."""
if platform.system() == "Windows": # pragma: no cover
mount_location = "T:\\"
elif platform.system() == "Darwin":
elif platform.system() == "Darwin": # pragma: no cover
mount_location = "/Volumes/TESTMOUNT"
else: # pragma: no cover
mount_location = os.path.join(os.path.curdir, "testmount")
Expand Down Expand Up @@ -50,11 +50,21 @@ def touch_mount_node(path: str, exist_ok: bool = False) -> str:
return node_location


def _copy_text_file(filename: str) -> None:
"""Copy a text file to the mounted test drive."""
template_bootloader = os.path.join("tests", "assets", filename)
bootloader_dest = os.path.join(get_mount(), filename)
shutil.copyfile(template_bootloader, bootloader_dest)


def copy_uf2_info() -> None:
"""Copy a bootloader file to the mounted test drive."""
template_bootloader = os.path.join("tests", "assets", "info_uf2.txt")
bootloader_dest = os.path.join(get_mount(), "info_uf2.txt")
shutil.copyfile(template_bootloader, bootloader_dest)
_copy_text_file("info_uf2.txt")


def copy_boot_out() -> None:
"""Copy a bootout file to the mounted test drive."""
_copy_text_file("boot_out.txt")


def copy_firmwares() -> None:
Expand Down
7 changes: 6 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ def test_install() -> None:
try:
uf2_info = tests.helpers.get_mount_node(circfirm.UF2INFO_FILE)
os.remove(uf2_info)

result = runner.invoke(cli, ["install", version])
assert result.exit_code == 1

tests.helpers.copy_boot_out()
result = runner.invoke(cli, ["install", version])
assert result.exit_code == 2
bootout = tests.helpers.get_mount_node(circfirm.BOOTOUT_FILE)
os.remove(bootout)
finally:
tests.helpers.copy_uf2_info()

Expand Down

0 comments on commit 9859a82

Please sign in to comment.