make sure booleans get in to booleans.conf

This commit is contained in:
Chris PeBenito 2006-03-02 23:39:28 +00:00
parent 0f27d98d94
commit 13a4943d30
2 changed files with 60 additions and 30 deletions

View File

@ -317,7 +317,7 @@ conf: $(MOD_CONF) $(BOOLEANS) $(GENERATED_TE) $(GENERATED_IF) $(GENERATED_FC)
$(MOD_CONF) $(BOOLEANS): $(POLXML) $(MOD_CONF) $(BOOLEANS): $(POLXML)
@echo "Updating $(MOD_CONF) and $(BOOLEANS)" @echo "Updating $(MOD_CONF) and $(BOOLEANS)"
$(verbose) $(GENDOC) -t $(BOOLEANS) -m $(MOD_CONF) -x $(POLXML) $(verbose) $(GENDOC) -b $(BOOLEANS) -m $(MOD_CONF) -x $(POLXML)
######################################## ########################################
# #

View File

@ -24,6 +24,10 @@ MOD_BASE = "base"
MOD_ENABLED = "module" MOD_ENABLED = "module"
MOD_DISABLED = "off" MOD_DISABLED = "off"
#booleans enabled and disabled values
BOOL_ENABLED = "true"
BOOL_DISABLED = "false"
#tunables enabled and disabled values #tunables enabled and disabled values
TUN_ENABLED = "true" TUN_ENABLED = "true"
TUN_DISABLED = "false" TUN_DISABLED = "false"
@ -48,34 +52,60 @@ def read_policy_xml(filename):
xml_fh.close() xml_fh.close()
return doc return doc
def gen_tunable_conf(doc, file_name, namevalue_list): def gen_booleans_conf(doc, file_name, namevalue_list):
""" """
Generates the tunable configuration file using the XML provided and the Generates the booleans configuration file using the XML provided and the
previous tunable configuration. previous booleans configuration.
""" """
for node in doc.getElementsByTagName("tunable"): for node in doc.getElementsByTagName("bool"):
for desc in node.getElementsByTagName("desc"): for desc in node.getElementsByTagName("desc"):
tun_desc = format_txt_desc(desc) bool_desc = format_txt_desc(desc)
s = string.split(tun_desc, "\n") s = string.split(bool_desc, "\n")
file_name.write("#\n") file_name.write("#\n")
for line in s: for line in s:
file_name.write("# %s\n" % line) file_name.write("# %s\n" % line)
tun_name = tun_val = None
bool_name = bool_val = None
for (name, value) in node.attributes.items(): for (name, value) in node.attributes.items():
if name == "name": if name == "name":
tun_name = value bool_name = value
elif name == "dftval": elif name == "dftval":
tun_val = value bool_val = value
if [tun_name,TUN_ENABLED] in namevalue_list: if [bool_name,BOOL_ENABLED] in namevalue_list:
tun_val = TUN_ENABLED bool_val = BOOL_ENABLED
elif [tun_name,TUN_DISABLED] in namevalue_list: elif [bool_name,BOOL_DISABLED] in namevalue_list:
tun_val = TUN_DISABLED bool_val = BOOL_DISABLED
if tun_name and tun_val: if bool_name and bool_val:
file_name.write("%s = %s\n\n" % (tun_name, tun_val)) file_name.write("%s = %s\n\n" % (bool_name, bool_val))
tun_name = tun_val = None bool_name = bool_val = None
# tunables are currently implemented as booleans
for node in doc.getElementsByTagName("tunable"):
for desc in node.getElementsByTagName("desc"):
bool_desc = format_txt_desc(desc)
s = string.split(bool_desc, "\n")
file_name.write("#\n")
for line in s:
file_name.write("# %s\n" % line)
bool_name = bool_val = None
for (name, value) in node.attributes.items():
if name == "name":
bool_name = value
elif name == "dftval":
bool_val = value
if [bool_name,BOOL_ENABLED] in namevalue_list:
bool_val = BOOL_ENABLED
elif [bool_name,BOOL_DISABLED] in namevalue_list:
bool_val = BOOL_DISABLED
if bool_name and bool_val:
file_name.write("%s = %s\n\n" % (bool_name, bool_val))
bool_name = bool_val = None
def gen_module_conf(doc, file_name, namevalue_list): def gen_module_conf(doc, file_name, namevalue_list):
""" """
@ -635,7 +665,7 @@ def usage():
sys.stdout.write("%s [-tmdT] -x <xmlfile>\n\n" % sys.argv[0]) sys.stdout.write("%s [-tmdT] -x <xmlfile>\n\n" % sys.argv[0])
sys.stdout.write("Options:\n") sys.stdout.write("Options:\n")
sys.stdout.write("-t --tunables <file> -- write tunable config to <file>\n") sys.stdout.write("-b --booleans <file> -- write boolean config to <file>\n")
sys.stdout.write("-m --modules <file> -- write module config to <file>\n") sys.stdout.write("-m --modules <file> -- write module config to <file>\n")
sys.stdout.write("-d --docs <dir> -- write interface documentation to <dir>\n") sys.stdout.write("-d --docs <dir> -- write interface documentation to <dir>\n")
sys.stdout.write("-x --xml <file> -- filename to read xml data from\n") sys.stdout.write("-x --xml <file> -- filename to read xml data from\n")
@ -644,18 +674,18 @@ def usage():
# MAIN PROGRAM # MAIN PROGRAM
try: try:
opts, args = getopt.getopt(sys.argv[1:], "t:m:d:x:T:", ["tunables","modules","docs","xml", "templates"]) opts, args = getopt.getopt(sys.argv[1:], "b:m:d:x:T:", ["booleans","modules","docs","xml", "templates"])
except getopt.GetoptError: except getopt.GetoptError:
usage() usage()
sys.exit(1) sys.exit(1)
tunables = modules = docsdir = None booleans = modules = docsdir = None
templatedir = "templates/" templatedir = "templates/"
xmlfile = "policy.xml" xmlfile = "policy.xml"
for opt, val in opts: for opt, val in opts:
if opt in ("-t", "--tunables"): if opt in ("-b", "--booleans"):
tunables = val booleans = val
if opt in ("-m", "--modules"): if opt in ("-m", "--modules"):
modules = val modules = val
if opt in ("-d", "--docs"): if opt in ("-d", "--docs"):
@ -667,24 +697,24 @@ for opt, val in opts:
doc = read_policy_xml(xmlfile) doc = read_policy_xml(xmlfile)
if tunables: if booleans:
namevalue_list = [] namevalue_list = []
if os.path.exists(tunables): if os.path.exists(booleans):
try: try:
conf = open(tunables, 'r') conf = open(booleans, 'r')
except: except:
error("Could not open tunables file for reading") error("Could not open booleans file for reading")
namevalue_list = get_conf(conf) namevalue_list = get_conf(conf)
conf.close() conf.close()
try: try:
conf = open(tunables, 'w') conf = open(booleans, 'w')
except: except:
error("Could not open tunables file for writing") error("Could not open booleans file for writing")
gen_tunable_conf(doc, conf, namevalue_list) gen_booleans_conf(doc, conf, namevalue_list)
conf.close() conf.close()