blob: 87eecb79f3d9efa1b749097437c62140f82b3423 (
plain)
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
|
#!/usr/bin/env python
# Copyright (C) 2024 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
'''
axivion2tasks.py - Convert Axivion JSON warnings into Qt Creator task files.
Process a file produced by an Axivion JSON export
Only style violations are implemented ATM.
SYNOPSIS
axivion2tasks.py < json-file > taskfile
'''
import json
import sys
from enum import Enum, auto
SV_MESSAGE_COLUMN = "message"
SV_PATH_COLUMN = "path"
SV_LINE_NUMBER_COLUMN = "line"
class Type(Enum):
Unknown = auto()
StyleViolation = auto()
def columns(data):
"""Extract the column keys."""
result = []
for col in data["columns"]:
result.append(col["key"])
return set(result)
def detect_type(data):
"""Determine file type."""
keys = columns(data)
if set([SV_MESSAGE_COLUMN, SV_PATH_COLUMN, SV_LINE_NUMBER_COLUMN]) <= keys:
return Type.StyleViolation
return Type.Unknown
def print_warning(path, line_number, text):
print(f"{path}\t{line_number}\twarn\t{text}")
def print_style_violations(data):
rows = data["rows"]
for row in rows:
print_warning(row[SV_PATH_COLUMN], row[SV_LINE_NUMBER_COLUMN], row[SV_MESSAGE_COLUMN])
return len(rows)
if __name__ == '__main__':
data = json.load(sys.stdin)
count = 0
file_type = detect_type(data)
if file_type == Type.StyleViolation:
count = print_style_violations(data)
if count:
print(f"{count} issue(s) found.", file=sys.stderr)
|