Total Complexity | 5 |
Total Lines | 30 |
Duplicated Lines | 0 % |
Coverage | 50% |
Changes | 0 |
1 | # Copyright 2022, Red Hat, Inc. |
||
2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
||
3 | 1 | import json |
|
4 | 1 | import logging |
|
5 | 1 | from io import BytesIO |
|
6 | |||
7 | 1 | from .report_generator import ReportGenerator |
|
8 | |||
9 | |||
10 | 1 | class JSONReportGenerator(ReportGenerator): |
|
11 | 1 | def __init__(self, parser): |
|
12 | super().__init__(parser) |
||
13 | self.get_report_dict = None |
||
14 | self.set_report_dictionary_source(self.report.as_dict_for_default_json) |
||
15 | |||
16 | 1 | def set_report_dictionary_source(self, source): |
|
17 | self.get_report_dict = source |
||
18 | |||
19 | 1 | def generate_report(self, debug_setting): |
|
20 | logging.warning("JSON Format is experimental output!") |
||
21 | indent = "\t" if debug_setting.no_minify else None |
||
22 | json_data = json.dumps(self.get_report_dict(), indent=indent) |
||
23 | return BytesIO(json_data.encode()) |
||
24 | |||
25 | |||
26 | 1 | class JSONEverythingReportGenerator(JSONReportGenerator): |
|
27 | 1 | def __init__(self, parser): |
|
28 | super().__init__(parser) |
||
29 | self.set_report_dictionary_source(self.report.as_dict) |
||
30 |