openscap_report.report_generators.json   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 30
ccs 10
cts 20
cp 0.5
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A JSONEverythingReportGenerator.__init__() 0 3 1
A JSONReportGenerator.generate_report() 0 5 2
A JSONReportGenerator.__init__() 0 4 1
A JSONReportGenerator.set_report_dictionary_source() 0 2 1
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