forked from KKalem/smarc2
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathrender_structure.py
More file actions
executable file
·77 lines (59 loc) · 2.67 KB
/
render_structure.py
File metadata and controls
executable file
·77 lines (59 loc) · 2.67 KB
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
77
#!/usr/bin/python3
import json, datetime
# some common stuff _every_ node has, to ignore
ignored = ["parameter_events",
"rosout",
"describe_parameters",
"get_parameter_types",
"get_parameters",
"list_parameters",
"set_parameters",
"set_parameters_atomically"]
with open("smarc2_structure.json", "r") as f:
file = json.load(f)
structure = file["structure"]
# construct one long string to record all our findings
# formatted as a markdown file with links to launchfiles
global s
s = "# SMaRC2 Packages, Launches and Nodes\n\n"
def addline(l):
global s
s += l + "\n\n"
addline("This file is auto-generated by [this script](./scripts/render_structure.py) and thus should not be edited by hand!")
addline("It is based on [this json](./smarc2_structure.json) which is generated by [this script](./scripts/launch_everything.py).")
addline(f"This list does not contain the common topics that all nodes have({ignored})")
addline(f"The **robot_name parameter** given to all launch files: {file['robot_name']}")
addline(f"**SMaRC2 Commit:** {file['hash']}")
dt = datetime.datetime.fromtimestamp(file['created'])
addline(f"**Created:** {file['created']} ({dt})")
for package_name, contents in structure.items():
addline(f"## [{package_name}](./{contents['path']})")
if(len(contents['launchfiles']) < 1):
addline("> This package did not have any launch files.")
continue
for launchfile in contents['launchfiles']:
# strip the last bit for the text
just_name = launchfile.split('/')[-1]
addline(f"### [{just_name}](./{launchfile})")
nodes = contents['launchfiles'][launchfile]['nodes']
if(len(nodes) < 1):
addline(f"> No nodes worked in this launch file!")
continue
for node_name, node_connections in nodes.items():
addline(f"#### {node_name}")
for title in node_connections:
if(len(node_connections[title]) < 1): continue
# we want to ignore some of these topics
# because they are shared by everything
clean_connections = []
for conn in node_connections[title]:
last_part = conn[0].split('/')[-1]
if last_part not in ignored:
clean_connections.append(conn)
if(len(clean_connections) < 1): continue
addline(f"##### {title}")
for conn in clean_connections:
addline(f"- **{conn[0]}** :: *{conn[1]}*")
with open("smarc2_structure.md", 'w') as f:
f.write(s)
print("Markdown done~")