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

ssg.build_stig.add_references()   C

Complexity

Conditions 9

Size

Total Lines 41
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
cc 9
eloc 28
nop 2
dl 0
loc 41
ccs 0
cts 24
cp 0
crap 90
rs 6.6666
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