This repository was archived by the owner on Jun 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin.py
More file actions
101 lines (72 loc) · 2.88 KB
/
join.py
File metadata and controls
101 lines (72 loc) · 2.88 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#! /usr/bin/python3
import sys, json, os
def addBasePath(reports, basePath):
for report in reports:
# Only get reports from files
if 'location' not in report:
continue
report['location']['path'] = os.path.join(basePath, report['location']['path'])
def ReadReports(filenames: list):
'''Read in all reports'''
reports = []
for arg in filenames:
with open(arg) as file:
# Load json
fileReports = json.loads(file.read())
# Update locations to contain full path
if arg == "backend.json":
addBasePath(fileReports, 'src/backend')
elif arg == "frontend.json":
addBasePath(fileReports, 'src/dispatch-website')
reports.extend(fileReports)
return reports
def WriteReports(filename: str, reports: list):
'''Write out combined json'''
with open(filename, mode='w') as output:
print('[', end='', file=output)
for item in reports[:-1]:
print(json.dumps(item) + ',', file=output)
print(json.dumps(reports[-1]) + "]", file=output)
def ConstructErrorString(report: object):
'''Construct error string for report entry'''
line_begin = report['location']['lines']['begin'] if 'lines' in report['location'] else report['location']['positions']['begin']['line']
line_end = report['location']['lines']['end'] if 'lines' in report['location'] else report['location']['positions']['end']['line']
message = report['description']
engine = report['engine_name']
if line_begin == line_end:
line_string = "{0}".format(line_begin)
else:
line_string = "{0}-{1}".format(line_begin, line_end)
return "{0}: {1} [{2}]".format(line_string, message, engine)
def CollectErrors(reports: list):
files = {}
for report in reports:
# Skip non-file reports
if 'location' not in report:
continue
# Get file from report
file = report['location']['path']
# Create issue string
issue_string = ConstructErrorString(report)
if file in files:
files[file].append(issue_string)
else:
files[file] = [issue_string]
return files
def PrintReportStrings(reports_dict: dict):
for file, string_list in reports_dict.items():
string_list.sort() # Sort in order of beginning line
# Print errors
print("== {0} ({1} issue{2}) ==".format(file, len(string_list), 's' if len(string_list) > 1 else ''))
for error in string_list:
print(error)
print("") # Need a new line
def main(argv):
reports = ReadReports(argv[1:-1])
WriteReports(argv[-1], reports)
file_lists = CollectErrors(reports)
PrintReportStrings(file_lists)
# Clear out source files
[os.remove(x) for x in argv[1:-1]]
if __name__ == "__main__":
main(sys.argv)