-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: romanodanilo <[email protected]>
- Loading branch information
1 parent
839a1cf
commit f172607
Showing
2 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
report_modules/report_module_text/report_format_text.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import sys, os | ||
import logging | ||
import argparse | ||
|
||
from qc_baselib import Configuration, Result, IssueSeverity | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
|
||
def is_valid_file(parser, arg): | ||
if not os.path.exists(arg): | ||
parser.error(f"The file {arg} does not exist!") | ||
if not (arg.endswith(".xml") or arg.endswith(".xqar")): | ||
parser.error("The file must have an .xml or .xqar extension!") | ||
return arg | ||
|
||
|
||
def run_text_report(input_filename, report_filename): | ||
|
||
result = Result() | ||
result.load_from_file(input_filename) | ||
|
||
# Open the file in write mode initially to wipe its content | ||
report_file = open(report_filename, "w") | ||
report_file.close() | ||
|
||
# Open the file in append mode to add new content | ||
report_file = open(report_filename, "a") | ||
|
||
report_file.write("=" * 102 + "\n") | ||
report_file.write("Python Text Report Module - Pooled Results\n") | ||
report_file.write("=" * 102 + "\n") | ||
|
||
# Checker bundles | ||
for checker_bundle in result.get_checker_bundle_results(): | ||
report_file.write(f" CheckerBundle: {checker_bundle.name}\n") | ||
report_file.write(f" Build date: {checker_bundle.build_date}\n") | ||
report_file.write(f" Build version: {checker_bundle.version}\n") | ||
report_file.write(f" Description: {checker_bundle.description}\n") | ||
report_file.write(f" Summary: {checker_bundle.summary}\n") | ||
if len(checker_bundle.params) > 0: | ||
report_file.write(f" Parameters:\n") | ||
for param in checker_bundle.params: | ||
report_file.write(f" {param.name} = {param.value}\n") | ||
|
||
# Checkers | ||
report_file.write(" " + "=" * 20 + "\n") | ||
report_file.write(" " + "Checkers:\n") | ||
report_file.write(" " + "=" * 20 + "\n") | ||
|
||
for checker in checker_bundle.checkers: | ||
report_file.write(f" Checker: {checker.checker_id}\n") | ||
report_file.write(f" Description: {checker.description}\n") | ||
if checker.status is None: | ||
status_string = "" | ||
else: | ||
status_string = checker.status | ||
report_file.write(f" Status: {status_string}\n") | ||
report_file.write(f" Summary: {checker.summary}\n") | ||
|
||
# Issues | ||
report_file.write(" " + "=" * 20 + "\n") | ||
report_file.write(" " + "Issues:\n") | ||
report_file.write(" " + "=" * 20 + "\n") | ||
for issue in checker.issues: | ||
report_file.write(f" Issue: {issue.issue_id}\n") | ||
report_file.write( | ||
f" Description: {issue.description}\n" | ||
) | ||
report_file.write(f" Level: {issue.level}\n") | ||
# Addressed rules | ||
report_file.write(" " + "=" * 20 + "\n") | ||
report_file.write(" " + "Addressed rules:\n") | ||
report_file.write(" " + "=" * 20 + "\n") | ||
for addressed_rule in checker.addressed_rule: | ||
report_file.write( | ||
f" Addressed Rule: {addressed_rule.rule_uid}\n" | ||
) | ||
|
||
# Metadata | ||
report_file.write(" " + "=" * 20 + "\n") | ||
report_file.write(" " + "Metadata:\n") | ||
report_file.write(" " + "=" * 20 + "\n") | ||
|
||
for metadata in checker.metadata: | ||
report_file.write(f" Metadata: {metadata.key}\n") | ||
report_file.write(f" Value: {metadata.value}\n") | ||
report_file.write( | ||
f" Description: {metadata.description}\n" | ||
) | ||
|
||
report_file.close() | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Process XML configuration file.") | ||
parser.add_argument( | ||
"-c", | ||
"--config", | ||
type=lambda x: is_valid_file(parser, x), | ||
help="Path to the input configuration file. Must be a xml or xqar file", | ||
required=True, | ||
) | ||
args = parser.parse_args() | ||
|
||
input_file = args.config | ||
input_extension = os.path.splitext(input_file)[1] | ||
|
||
# Default params | ||
input_filename = "Result.xqar" | ||
report_filename = "Report.txt" | ||
|
||
if input_extension == ".xqar": | ||
input_filename = input_file | ||
|
||
if input_extension == ".xml": | ||
configuration = Configuration() | ||
configuration.load_from_file(input_file) | ||
input_filename = configuration.get_config_param("strInputFile") | ||
report_filename = configuration.get_config_param("strReportFile") | ||
|
||
logging.debug(f"input_filename {input_filename}") | ||
logging.debug(f"report_filename {report_filename}") | ||
|
||
run_text_report(input_filename, report_filename) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright 2024, ASAM e.V. | ||
# This Source Code Form is subject to the terms of the Mozilla | ||
# Public License, v. 2.0. If a copy of the MPL was not distributed | ||
# with this file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
readonly CONFIG_FILE=$1 | ||
|
||
python3 report_format_text.py -c $CONFIG_FILE |