Debian Codegraph @

tests/bindings/python/oval_helpers.py

raw symbols SCIP
1 #!/usr/bin/env python
2
3 # Author:
4 # Dominique Blaze <[email protected]>
5 #
6 # Description:
7 # Helpers functions in order to factorize other tests features
8 # It can potentially be integrated later in the high layer python api
9 # to provide convenience utilities.
10 #
11
12 from import_handler import oscap
13
14
15 def browse_criteria(crit_node, mode=0):
16 '''
17 Browse recursively criteria of an oval test and build a representation of it
18 First list item is the operator, and the next ones are the tests
19 If the item is a list, it's a criteria (else a criterion, or string for an
20 extended defintion , or None for OVAL_NODETYPE_UNKNOWN
21
22 Ex: [operator, "extended def", [operator, test_result2, test_result3]]
23
24 Mode : with mode = 0, test_result is the swig object oval_test_result
25 with mode = 1, test result is a a tuple like (test_subtype, test_result)
26 for instance (oscap.oval.OVAL_LINUX_DPKG_INFO, OVAL_FAMILY_LINUX
27 oscap.xccdf.XCCDF_RESULT_PASS)
28 '''
29
30 # init the critria list
31 rs = list()
32
33 if crit_node.get_type() == oscap.oval.OVAL_NODETYPE_CRITERIA:
34 for c in crit_node.get_subnodes():
35 rs.append(browse_criteria(c, mode))
36
37 elif crit_node.get_type() == oscap.oval.OVAL_NODETYPE_CRITERION:
38 if mode == 0:
39 rs.append(crit_node.get_test())
40 elif mode == 1:
41 rs.append((crit_node.get_test().get_test().get_family(),
42 crit_node.get_test().get_test().get_subtype(),
43 crit_node.get_test().get_result()))
44 else:
45 raise ValueError("param mode in browse_criteria should be 0 or 1")
46
47 elif crit_node.get_type() == oscal.oval.OVAL_NODETYPE_EXTENDDEF: # !!! TODO !!!
48 rs.append("extended def")
49
50 else:
51 rs.append(None)
52
53 return rs