Skip to content

Commit

Permalink
convert copy script to python
Browse files Browse the repository at this point in the history
  • Loading branch information
the-it committed Oct 3, 2021
1 parent a4f26a5 commit b54482a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
LASTRUN
venv
44 changes: 30 additions & 14 deletions run
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
#!/bin/bash

NOW=$(date +%s)
LASTRUN=$(cat LASTRUN)
for PY in *.py; do
CHANGED=$(date +%s -r $PY)
if (( $CHANGED >= $LASTRUN )); then
echo "$PY..."
ampy --port /dev/ttyACM0 put $PY /$PY
fi
done

echo $NOW > LASTRUN
ampy --port /dev/ttyACM0 run main.py
#!/usr/local/bin/python3
import argparse
import contextlib
import os
import subprocess
from datetime import datetime
from pathlib import Path

parser = argparse.ArgumentParser()
parser.add_argument('--device', action='store_true', default="/dev/ttyACM0")
args = parser.parse_args()

CURRENT_DIR = Path(__file__).parent
NOW = datetime.now()
with contextlib.suppress(FileNotFoundError):
LASTRUN = datetime(year=2000, month=1, day=1)
with open("LASTRUN") as last_run_file:
LASTRUN = datetime.utcfromtimestamp(int(last_run_file.read()))
with open("LASTRUN", "w") as last_run_file:
last_run_file.write(NOW.strftime("%s"))

for file in os.listdir(CURRENT_DIR):
if file.split(".")[-1] == "py":
if datetime.utcfromtimestamp(os.path.getmtime(CURRENT_DIR.joinpath(file))) > LASTRUN:
print(f"copy: {file}")
subprocess.run(["ampy", "--port", args.device, "put", file, f"/{file}"])
else:
print(f"up to date: {file}")

subprocess.run(["ampy", "--port", args.device, "run", "main.py"])

0 comments on commit b54482a

Please sign in to comment.