forked from malcolmholmes/pico-clock-green-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
LASTRUN | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) |