Debian Codegraph @

tests/sce/script_tester.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 #
4 # Copyright 2011 Red Hat Inc., Durham, North Carolina.
5 # All Rights Reserved.
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #
21 # Authors:
22 # "Martin Preisler" <[email protected]>
23 #
24
25 import argparse
26
27 parser = argparse.ArgumentParser(description = "Performs checks by given scripts and returns the result")
28 parser.add_argument("globs", metavar = "F", type = str, nargs = "+",
29 help = "File or glob of the check script to process")
30
31 args = parser.parse_args()
32
33 import glob
34 files = []
35 for g in args.globs:
36 gfiles = glob.glob(g)
37 files.extend(gfiles)
38 if len(gfiles) == 0:
39 print("No file matches '%s'" % (g))
40
41 import os
42
43 xccdf_result_map = dict()
44 xccdf_result_map["XCCDF_RESULT_PASS"] = 101
45 xccdf_result_map["XCCDF_RESULT_FAIL"] = 102
46 xccdf_result_map["XCCDF_RESULT_ERROR"] = 103
47 xccdf_result_map["XCCDF_RESULT_UNKNOWN"] = 104
48 xccdf_result_map["XCCDF_RESULT_NOT_APPLICABLE"] = 105
49 xccdf_result_map["XCCDF_RESULT_NOT_CHECKED"] = 106
50 xccdf_result_map["XCCDF_RESULT_NOT_SELECTED"] = 107
51 xccdf_result_map["XCCDF_RESULT_INFORMATIONAL"] = 108
52 xccdf_result_map["XCCDF_RESULT_FIXED"] = 109
53
54 xccdf_reverse_result_map = dict()
55 for key, value in xccdf_result_map.items():
56 xccdf_reverse_result_map[value] = key
57
58 # set all XCCDF result types as environment variables
59 # (this is especially useful for bash scripts)
60 for key, value in xccdf_result_map.items():
61 os.environ[key] = str(value)
62
63 import subprocess
64
65 for file_path in files:
66 result = subprocess.call(["./%s" % (file_path)])
67 if result in xccdf_reverse_result_map:
68 result_text = xccdf_reverse_result_map[result]
69 else:
70 result_text = "Unknown exit code %i" % (result)
71 print("Result of '%s' is %s" % (file_path, result_text))
72