diff options
author | Friedemann Kleint <[email protected]> | 2024-06-25 16:06:30 +0200 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2024-07-10 08:11:57 +0000 |
commit | 32af4964cef1981bb1d043006326324f82bae74b (patch) | |
tree | 74061303ffab779486fd96988bf26e7b367db456 | |
parent | e1560a3c7c2c7c735133b5bfbff4994ba10d06f7 (diff) |
Add a converter for converting an exported Axivion JSON table into a task file
Change-Id: If722af7472cc174e23a9d98e266874660e86842f
Reviewed-by: Christian Stenger <[email protected]>
-rwxr-xr-x | scripts/axivion2tasks.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/scripts/axivion2tasks.py b/scripts/axivion2tasks.py new file mode 100755 index 00000000000..87eecb79f3d --- /dev/null +++ b/scripts/axivion2tasks.py @@ -0,0 +1,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) |