-
Notifications
You must be signed in to change notification settings - Fork 10
/
run
executable file
·44 lines (37 loc) · 1.37 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import argparse
import contextlib
import os
import subprocess
import sys
from datetime import datetime
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument('--device', action='store_true',
default="/dev/cu.usbmodem14101")
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"))
found_config = False
for file in os.listdir(CURRENT_DIR):
if file.split(".")[-1] == "py" or file.split(".")[-1] == "json":
if file == "configuration.py":
found_config = True
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}")
if not found_config:
print("You need to create a configuration.py file. See the README.")
sys.exit("No configuration.py file found")
print("Uploaded code")
print("")
subprocess.run(["ampy", "--port", args.device, "run", "main.py"])