Completed
Push — master ( 291ee9...9d841e )
by Matěj
20s queued 12s
created

ssg._xml   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 6

3 Functions

Rating   Name   Duplication   Size   Complexity  
A map_elements_to_their_ids() 0 16 3
A oval_generated_header() 0 10 1
A parse_file() 0 8 2
1
import platform
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
from ssg._constants import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like ssg._constants should generally be avoided.
Loading history...
Unused Code introduced by
datetime was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
os was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JINJA_MACROS_DEFINITIONS was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
datastream_namespace was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ocil_namespace was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
oval_footer was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
oval_namespace was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ocil_cs was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
xccdf_header was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
xccdf_footer was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
bash_system was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ansible_system was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
puppet_system was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
anaconda_system was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
cce_uri was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
stig_ns was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ssg_version_uri was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_VENDOR was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_DS_STRING was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_GROUP was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_GROUP_PCIDSS was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_GROUP_VAL was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_GROUP_NON_PCI was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
XCCDF11_NS was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
XCCDF12_NS was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
min_ansible_version was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ansible_version_requirement_pre_task_name was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
PKG_MANAGER_TO_SYSTEM was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
disa_cciuri was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
disa_srguri was imported with wildcard, but is not used.
Loading history...
4
5
6
try:
7
    from xml.etree import cElementTree as ElementTree
8
except ImportError as e:
0 ignored issues
show
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
9
    print(e)
10
    import cElementTree as ElementTree
11
12
13
def oval_generated_header(product_name, schema_version, ssg_version):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
14
    return xml_version + oval_header + \
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable oval_header does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable xml_version does not seem to be defined.
Loading history...
15
        """
16
    <generator>
17
        <oval:product_name>%s from SCAP Security Guide</oval:product_name>
18
        <oval:product_version>ssg: %s, python: %s</oval:product_version>
19
        <oval:schema_version>%s</oval:schema_version>
20
        <oval:timestamp>%s</oval:timestamp>
21
    </generator>""" % (product_name, ssg_version, platform.python_version(),
22
                       schema_version, timestamp)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable timestamp does not seem to be defined.
Loading history...
23
24
25
def parse_file(filename):
26
    """
27
    Given a filename, return the corresponding ElementTree
28
    """
29
    with open(filename, 'r') as xml_file:
30
        filestring = xml_file.read()
31
        tree = ElementTree.fromstring(filestring)
32
    return tree
33
34
35
def map_elements_to_their_ids(tree, xpath_expr):
36
    """
37
    Given an ElementTree and an XPath expression,
38
    iterate through matching elements and create 1:1 id->element mapping.
39
40
    Raises AssertionError if a matching element doesn't have the ``id``
41
    attribute.
42
43
    Returns mapping as a dictionary
44
    """
45
    aggregated = {}
46
    for element in tree.findall(xpath_expr):
47
        element_id = element.get("id")
48
        assert element_id is not None
49
        aggregated[element_id] = element
50
    return aggregated
51