-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutility.py
executable file
·62 lines (47 loc) · 1.58 KB
/
utility.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import argparse
import subprocess
from time import sleep
from pathlib import Path
def run(cmd, timeout=1):
"""Older ESP32 require timeout after shell command."""
subprocess.run(cmd)
sleep(timeout)
def install(device=None, debug=None, **kwargs):
base = ["mpremote", "resume"]
libraries = []
files = []
folders = []
if device:
base += ["connect", f"{device}"]
# allows you keep keys in a different file
if Path("secret.json").is_file():
print("picked up secret.json")
files = [Path("secret.json")]
if not debug:
input("Copying boot, CTRL+C to abort")
files += ["src/boot.py"]
for lib in libraries:
run(base + ["mip", "install", lib])
folders = [Path(f) for f in folders]
for folder in folders:
run(base + ["fs", "cp", "-r", folder.as_posix(), ":"])
files = [Path(f) for f in files]
for file in files:
if file.name == "secret.json":
run(base + ["fs", "cp", f"{file}", ":config.json"])
else:
run(base + ["fs", "cp", f"{file}", f":{file.name}"])
run(base + ["reset"])
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Utility to automate install ESP32"
)
parser.add_argument(
"--device",
type=str,
nargs="?",
help="Give device name, e.g. COM8 or ttyS8 for Windows and linux, respectively.",
)
parser.add_argument("--debug", action="store_true")
args = parser.parse_args()
install(**vars(args))