mirror of
https://github.com/Crocmagnon/plant-badger.git
synced 2024-11-24 10:28:01 +01:00
Allow updating code on all boards without wiping
This commit is contained in:
parent
1e7a54c8d6
commit
7dff437b6f
1 changed files with 30 additions and 25 deletions
55
tasks.py
55
tasks.py
|
@ -23,40 +23,29 @@ def list_boards(c: Context) -> None:
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def provision_all(c: Context) -> None:
|
def provision_all(c: Context, *, initial: bool = True) -> None:
|
||||||
"""Provision all connected boards sequentially."""
|
"""Provision all connected boards sequentially."""
|
||||||
# Here's an example output of `mpremote devs`:
|
ids = get_all_board_ids()
|
||||||
# /dev/cu.Bluetooth-Incoming-Port None 0000:0000 None None
|
|
||||||
# /dev/cu.usbmodem101 e6614864d35f9934 2e8a:0005 MicroPython Board in FS mode
|
|
||||||
# /dev/cu.usbmodem112201 e6614864d3417f36 2e8a:0005 MicroPython Board in FS mode
|
|
||||||
|
|
||||||
output = subprocess.run(["mpremote", "devs"], stdout=subprocess.PIPE).stdout.decode(
|
|
||||||
"utf-8"
|
|
||||||
)
|
|
||||||
lines = output.splitlines()
|
|
||||||
ids = []
|
|
||||||
for line in lines:
|
|
||||||
if "Bluetooth" not in line:
|
|
||||||
ids.append(line.split()[1])
|
|
||||||
|
|
||||||
for board_id in ids:
|
for board_id in ids:
|
||||||
provision(c, board_id)
|
provision(c, board_id, initial=initial)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def provision(c: Context, board_id: str) -> None:
|
def provision(c: Context, board_id: str, *, initial: bool = True) -> None:
|
||||||
"""Install dependencies and copy project files to the board."""
|
"""Install dependencies and copy project files to the board."""
|
||||||
prepare(board_id)
|
prepare(board_id)
|
||||||
download_image(c, board_id)
|
download_image(c, board_id)
|
||||||
wipe(c, board_id)
|
if initial:
|
||||||
with c.cd(SRC_DIR):
|
wipe(c, board_id)
|
||||||
if MICROPYTHON_DEPENDENCIES:
|
with c.cd(SRC_DIR):
|
||||||
deps = " ".join(MICROPYTHON_DEPENDENCIES)
|
if MICROPYTHON_DEPENDENCIES:
|
||||||
c.run(
|
deps = " ".join(MICROPYTHON_DEPENDENCIES)
|
||||||
f"mpremote connect id:{board_id} " f"mip install {deps}",
|
c.run(
|
||||||
pty=True,
|
f"mpremote connect id:{board_id} " f"mip install {deps}",
|
||||||
echo=True,
|
pty=True,
|
||||||
)
|
echo=True,
|
||||||
|
)
|
||||||
update_code(c, board_id)
|
update_code(c, board_id)
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,6 +135,22 @@ def prepare(board_id: str) -> None:
|
||||||
f.write(ast.unparse(secrets))
|
f.write(ast.unparse(secrets))
|
||||||
|
|
||||||
|
|
||||||
|
def get_all_board_ids():
|
||||||
|
# Here's an example output of `mpremote devs`:
|
||||||
|
# /dev/cu.Bluetooth-Incoming-Port None 0000:0000 None None
|
||||||
|
# /dev/cu.usbmodem101 e6614864d35f9934 2e8a:0005 MicroPython Board in FS mode
|
||||||
|
# /dev/cu.usbmodem112201 e6614864d3417f36 2e8a:0005 MicroPython Board in FS mode
|
||||||
|
output = subprocess.run(["mpremote", "devs"], stdout=subprocess.PIPE).stdout.decode(
|
||||||
|
"utf-8"
|
||||||
|
)
|
||||||
|
lines = output.splitlines()
|
||||||
|
ids = []
|
||||||
|
for line in lines:
|
||||||
|
if "Bluetooth" not in line:
|
||||||
|
ids.append(line.split()[1])
|
||||||
|
return ids
|
||||||
|
|
||||||
|
|
||||||
def get_provisioning(board_id: str) -> dict[str, str]:
|
def get_provisioning(board_id: str) -> dict[str, str]:
|
||||||
# load provisioning.yaml
|
# load provisioning.yaml
|
||||||
with (BASE_DIR / "provisioning.yaml").open() as f:
|
with (BASE_DIR / "provisioning.yaml").open() as f:
|
||||||
|
|
Loading…
Reference in a new issue