Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deploy to device. #32

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions ci/deploy_to_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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}")
Expand All @@ -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 []

Expand Down