diff options
author | cgzones <cgzones@googlemail.com> | 2017-03-15 00:32:11 +0100 |
---|---|---|
committer | Jason Zaman <jason@perfinion.com> | 2017-03-30 19:37:14 +0800 |
commit | 9bd79f9a459858f57d172ffcfbf2d6984e727456 (patch) | |
tree | d43b250a2e0e733e5af9d7a4c698362257b7d3f3 /support/segenxml.py | |
parent | Module version bump for fixes from cgzones. (diff) | |
download | hardened-refpolicy-9bd79f9a459858f57d172ffcfbf2d6984e727456.tar.gz hardened-refpolicy-9bd79f9a459858f57d172ffcfbf2d6984e727456.tar.bz2 hardened-refpolicy-9bd79f9a459858f57d172ffcfbf2d6984e727456.zip |
convert build scripts to python3
Diffstat (limited to 'support/segenxml.py')
-rw-r--r-- | support/segenxml.py | 68 |
1 files changed, 4 insertions, 64 deletions
diff --git a/support/segenxml.py b/support/segenxml.py index ab8ee520..383428df 100644 --- a/support/segenxml.py +++ b/support/segenxml.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # Author(s): Donald Miner <dminer@tresys.com> # Dave Sugar <dsugar@tresys.com> @@ -17,21 +17,12 @@ import sys import os -import glob import re import getopt # GLOBALS # Default values of command line arguments: -warn = False -meta = "metadata" -third_party = "third-party" -layers = {} -tunable_files = [] -bool_files = [] -xml_tunable_files = [] -xml_bool_files = [] output_dir = "" # Pre compiled regular expressions: @@ -83,7 +74,7 @@ def getModuleXML(file_name): module_file = open(module_if, "r") module_code = module_file.readlines() module_file.close() - except: + except OSError: warning("cannot open file %s for read, skipping" % file_name) return [] @@ -200,7 +191,7 @@ def getTunableXML(file_name, kind): tunable_file = open(file_name, "r") tunable_code = tunable_file.readlines() tunable_file.close() - except: + except OSError: warning("cannot open file %s for read, skipping" % file_name) return [] @@ -250,61 +241,11 @@ def getTunableXML(file_name, kind): for tunable_line in tunable_buf: xml_outfile.write (tunable_line) xml_outfile.close() - except: + except OSError: warning ("cannot write to file %s, skipping creation" % xmlfile) return tunable_buf -def getXMLFileContents (file_name): - ''' - Return all the XML in the file specified. - ''' - - tunable_buf = [] - # Try to open the xml file for this type of file - # append the contents to the buffer. - try: - tunable_xml = open(file_name, "r") - tunable_buf += tunable_xml.readlines() - tunable_xml.close() - except: - warning("cannot open file %s for read, assuming no data" % file_name) - - return tunable_buf - -def getPolicyXML(): - ''' - Return the compelete reference policy XML documentation through a list, - one line per item. - ''' - - policy_buf = [] - policy_buf.append("<policy>\n") - - # Add to the XML each layer specified by the user. - for layer in layers.keys (): - policy_buf += getLayerXML(layer, layers[layer]) - - # Add to the XML each tunable file specified by the user. - for tunable_file in tunable_files: - policy_buf += getTunableXML(tunable_file, "tunable") - - # Add to the XML each XML tunable file specified by the user. - for tunable_file in xml_tunable_files: - policy_buf += getXMLFileContents (tunable_file) - - # Add to the XML each bool file specified by the user. - for bool_file in bool_files: - policy_buf += getTunableXML(bool_file, "bool") - - # Add to the XML each XML bool file specified by the user. - for bool_file in xml_bool_files: - policy_buf += getXMLFileContents (bool_file) - - policy_buf.append("</policy>\n") - - return policy_buf - def usage(): """ Displays a message describing the proper usage of this script. @@ -388,4 +329,3 @@ elif boolean: else: usage() sys.exit(2) - |