forked from malcolmholmes/pico-clock-green-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·30 lines (26 loc) · 1.02 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env 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"])