From 8eb6a22235611cdb6e9c775817582ea4e21e42f4 Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Fri, 20 Sep 2024 08:29:34 +0100 Subject: [PATCH] Fix deploy to device. (#32) We were not reading the file list correctly. --- ci/deploy_to_device.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/ci/deploy_to_device.py b/ci/deploy_to_device.py index cd518c6..296b72b 100644 --- a/ci/deploy_to_device.py +++ b/ci/deploy_to_device.py @@ -12,7 +12,7 @@ def deploy(): """Deploy files to a device via mpremote""" try: - deploy_py_files(Path("docs/source/examples"), ":") + deploy_py_files(Path("docs/source/examples"), ":", clear=False) deploy_py_files(Path("docs/source/examples/devices"), ":/devices") deploy_py_files(Path("src/ultimo"), ":/lib/ultimo") deploy_py_files(Path("src/ultimo_machine"), ":/lib/ultimo_machine") @@ -22,21 +22,24 @@ def deploy(): print(exc.stderr) raise -def deploy_py_files(path: Path, destination): +def deploy_py_files(path: Path, destination, clear=True): try: mpremote("mkdir", destination) except subprocess.CalledProcessError as exc: - # path exists, clear out old files - print('remove', listdir(destination)) - for file in listdir(destination): - file = file.decode('utf-8') - if not file.endswith('.py'): - continue - try: - mpremote("rm", f"{destination}/{file}") - except subprocess.CalledProcessError as exc: - # probably a directory - pass + if clear: + # path exists, clear out old files + print('remove', destination, '...') + for file in listdir(destination): + file = file.decode('utf-8') + if not file.endswith('.py'): + continue + print('remove', f"{destination}/{file}") + try: + mpremote("rm", f"{destination}/{file}") + except subprocess.CalledProcessError as exc: + # probably a directory + print('failed') + pass for file in path.glob("*.py"): mpremote("cp", str(file), f"{destination}/{file.name}") @@ -45,8 +48,8 @@ def deploy_py_files(path: Path, destination): def listdir(directory): listing = mpremote("ls", directory) if listing is not None: - listing = listing.splitlines(1)[1] - return listing.split()[1::2] + lines = listing.splitlines()[1:] + return [line.split()[1] for line in lines] else: return []