forked from RamiAwar/fastabm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverage_to_md.py
49 lines (40 loc) · 1.02 KB
/
coverage_to_md.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
import sys
lines = None
with open(sys.argv[1]) as f:
lines = f.readlines()
# Find coverage
start_index = 0
for i, line in enumerate(lines):
if line.split()[0] == "Name":
start_index = i
elif line.split()[0] == "TOTAL":
stop_index = i
# Build table header
header = ["|"]
separator = ["|"]
headers = lines[start_index].split()
for i, name in enumerate(headers):
header.append(name)
header.append("|")
if i == 0:
separator.append(":-------------")
elif i == len(headers):
separator.append("-----------:")
else:
separator.append(":----------:")
separator.append("|")
# Build table body
body = []
start_index += 2
stop_index += 1
for line in lines[start_index:stop_index]:
x = ["|"]
for word in line.split():
if word[0] == "-":
break
x.extend([word, "|"])
if len(x) > 1:
body.append(" ".join(x))
table = [" ".join(header), " ".join(separator), *body]
with open("table.md", "w") as f:
f.write("\n".join(table))