| Total Complexity | 8 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Coverage | 94.74% |
| Changes | 0 | ||
| 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 |