RemediationParser.get_remediation()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 10
ccs 3
cts 3
cp 1
rs 9.95
c 0
b 0
f 0
cc 1
nop 2
crap 1
1
# Copyright 2022, Red Hat, Inc.
2
# SPDX-License-Identifier: LGPL-2.1-or-later
3
4 1
from lxml import etree
5
6 1
from ..data_structures import Remediation
7
8
9 1
class RemediationParser():
10 1
    def __init__(self, ref_values):
11 1
        self.ref_values = ref_values
12
13 1
    def replace_sub_tag(self, tag):
14 1
        return self.ref_values.get(tag.get("idref"))
15
16 1
    def _get_remediation_code(self, fix):
17 1
        str_fix = fix.text
18 1
        for child in fix:
19 1
            if str_fix is None:
20
                str_fix = ""
21 1
            if etree.QName(child).localname == "sub":
22 1
                str_fix += self.replace_sub_tag(child)
23 1
            str_fix += child.tail if child.tail is not None else ""
24 1
        return str_fix
25
26 1
    def get_remediation(self, fix):
27 1
        fix_dict = {
28
            "remediation_id": fix.get("id"),
29
            "system": fix.get("system"),
30
            "complexity": fix.get("complexity", ""),
31
            "disruption": fix.get("disruption", ""),
32
            "strategy": fix.get("strategy", ""),
33
            "fix": self._get_remediation_code(fix),
34
        }
35
        return Remediation(**fix_dict)
36