forked from jamesfowkes/raat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_example_sketch.py
76 lines (56 loc) · 2.19 KB
/
create_example_sketch.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
""" create_all_example_sketches.py
Usage:
create_all_example_sketches.py <target> [-v] [--sketchbook=<sketchbook_path>]
Options:
-v, --verbose Output extra logging information
"""
import sys
import os
import logging
import docopt
from pathlib import Path
from raat import parser
from raat_runner import make, get_sketch_directory
import arduino_cli_interface
def find_sketchbook_path():
POSSIBLE_SKETCHBOOK_PATHS = ["~/sketchbook",
"~/Arduino", "~/Documents/Arduino"]
for possible_sketchbook_path in POSSIBLE_SKETCHBOOK_PATHS:
candidate = Path(possible_sketchbook_path).expanduser()
if candidate.exists():
return candidate
return None
if __name__ == "__main__":
args = docopt.docopt(__doc__)
target_example_name = args["<target>"]
sketchbook_path = None
if "--sketchbook" in args and args["--sketchbook"]:
sketchbook_path = Path(args["--sketchbook"]).expanduser()
else:
sketchbook_path = find_sketchbook_path()
if sketchbook_path is None:
print("No sketchbook found")
sys.exit(1)
if (args["--verbose"]):
logging.basicConfig(level=logging.INFO)
else:
logging.basicConfig(level=logging.WARNING)
found_example = False
for possible_target_type in ["devices", "parameters", "modules"]:
for root, directories, files in os.walk("raat/{}".format(possible_target_type)):
if target_example_name in root:
for f in files:
if f == "example.xml":
found_example = Path.joinpath(Path(root), Path(f))
print("Found {}".format(str(found_example)))
break
if found_example:
print("Trying to build {}".format(found_example))
board, raat_config = parser.parse_file(Path(found_example))
make(board, raat_config, sketchbook_path)
sketch_directory = get_sketch_directory(
sketchbook_path, board.sketch_path().parent)
cli = arduino_cli_interface.ArduinoCLIInterface()
cli.verify(board, sketch_directory)
else:
print("Could not find example for {}".format(target_example_name))