Skip to content

Commit

Permalink
bundle ota update with yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sasatani committed Nov 2, 2024
1 parent f614735 commit 3eae8ad
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions miniscope_io/cli/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import click
import yaml

from miniscope_io.device_update import DevUpdate
from miniscope_io.models.devupdate import DeviceCommand
Expand Down Expand Up @@ -37,13 +38,20 @@
type=int,
help="Value to set. Must be used with --target and cannot be used with --restart.",
)
@click.option(
"-c",
"--config",
required=False,
type=click.Path(exists=True, dir_okay=False),
help="YAML file with configuration to update. Specify target and value pairs in the file.",
)
@click.option(
"--reboot",
is_flag=True,
type=bool,
help="Restart the device. Cannot be used with --target or --value.",
)
def update(port: str, target: str, value: int, device_id: int, reboot: bool) -> None:
def update(port: str, target: str, value: int, device_id: int, reboot: bool, config: str) -> None:
"""
Update device configuration or restart it.
"""
Expand All @@ -52,11 +60,17 @@ def update(port: str, target: str, value: int, device_id: int, reboot: bool) ->
if (target and not value) or (value and not target):
raise click.UsageError("Both --target and --value are required if one is specified.")

if (target or value) and reboot:
raise click.UsageError("Options --target/--value and --restart cannot be used together.")

if ((target or value) and reboot) or (config and reboot) or (config and (target or value)):
raise click.UsageError(
"Options --target/--value and --restart" " and --config are mutually exclusive."
)
if target and value:
DevUpdate(port=port, target=target, value=value, device_id=device_id)
elif config:
with open(config) as f:
config_file = yaml.safe_load(f)
for key, value in config_file:
DevUpdate(port=port, target=key, value=value, device_id=device_id)
elif reboot:
DevUpdate(port=port, target="DEVICE", value=DeviceCommand.REBOOT.value, device_id=device_id)
else:
Expand Down

0 comments on commit 3eae8ad

Please sign in to comment.