-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci_aggregate.py
86 lines (69 loc) · 2.69 KB
/
ci_aggregate.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
77
78
79
80
81
82
83
84
85
86
#! /usr/bin/env python3
"""
usage: ci_aggregate.py [-h] boards [result_directory]
positional arguments:
boards List of board to test
result_directory Result directory (default: None)
optional arguments:
-h, --help show this help message and exit
"""
import os
import re
import argparse
def list_from_string(list_str=None):
"""Get list of items from `list_str`
>>> list_from_string(None)
[]
>>> list_from_string("")
[]
>>> list_from_string(" ")
[]
>>> list_from_string("a")
['a']
>>> list_from_string("a ")
['a']
>>> list_from_string("a b c")
['a', 'b', 'c']
"""
value = (list_str or '').split(' ')
return [v for v in value if v]
def _board_results_in_dir(dir):
return next(os.walk(os.path.abspath(dir)))[1]
def _append_board_to_test_location(text, board):
return re.sub(r'(\[.*\])(\()(.*\))', r"\1({}/\3".format(board), text)
def aggregate_results(results_dir, boards, echo=True):
"""Aggregate all results for boards presents in results_dir"""
if boards is None:
boards = _board_results_in_dir(results_dir)
failuresummary = os.path.abspath(os.path.join(results_dir,
'failuresummary.md'))
with open(failuresummary, "w+") as failuresummary_file:
for board in boards:
boards_result_dir = os.path.abspath(
os.path.join(
results_dir,
'{}/failuresummary.md'.format(board)))
try:
with open(boards_result_dir) as board_failuresummary:
separator = "\n### {}/failuresummary\n\n".format(board)
failuresummary_file.write(separator)
for line in board_failuresummary:
line = _append_board_to_test_location(line, board)
failuresummary_file.write(line)
except FileNotFoundError:
print("results for {} not found in results_dir {}"
.format(board, results_dir))
if echo is True:
with open(failuresummary, "r") as failuresummary_file:
print(failuresummary_file.read())
PARSER = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
PARSER.add_argument('result_directory',
help='Result directory')
PARSER.add_argument('--boards',
type=list_from_string,
default=None,
help='List of board to test')
if __name__ == '__main__':
args = PARSER.parse_args()
aggregate_results(results_dir=args.result_directory, boards=args.boards)