Test Failed
Push — master ( f41b3f...0bcc33 )
by Matěj
03:22 queued 37s
created

ssg.build_stig.map_versions_to_rule_ids()   A

Complexity

Conditions 5

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 24.6646

Importance

Changes 0
Metric Value
cc 5
eloc 15
nop 1
dl 0
loc 18
ccs 1
cts 13
cp 0.0769
crap 24.6646
rs 9.1832
c 0
b 0
f 0
1 2
from __future__ import absolute_import
2 2
from __future__ import print_function
3
4 2
import sys
5
6 2
from .xml import ElementTree as ET
7 2
from .constants import XCCDF11_NS
8
9
10 2
def map_versions_to_rule_ids(reference_file_name):
11
    try:
12
        reference_root = ET.parse(reference_file_name)
13
    except IOError:
14
        print(
15
            "INFO: DISA STIG Reference file not found for this platform: %s" %
16
            reference_file_name)
17
        sys.exit(0)
18
19
    reference_rules = reference_root.findall('.//{%s}Rule' % XCCDF11_NS)
20
21
    dictionary = {}
22
23
    for rule in reference_rules:
24
        version = rule.find('.//{%s}version' % XCCDF11_NS)
25
        if version is not None and version.text:
26
            dictionary[version.text] = rule.get('id')
27
    return dictionary
28