speed improvement

This commit is contained in:
Chris PeBenito 2005-06-09 20:53:45 +00:00
parent 588ffaeb7f
commit 5d9417870c

View File

@ -16,8 +16,10 @@ import sys
import getopt import getopt
import pyplate import pyplate
import os import os
from xml.dom.ext import * import string
from xml.dom.ext.reader import Sax2 #from xml.dom.ext import *
#from xml.dom.ext.reader import Sax2
from xml.dom.minidom import parse, parseString
def read_policy_xml(filename): def read_policy_xml(filename):
try: try:
@ -26,8 +28,9 @@ def read_policy_xml(filename):
error("error opening " + filename) error("error opening " + filename)
try: try:
reader = Sax2.Reader() #reader = Sax2.Reader()
doc = reader.fromString(xml_fh.read()) #doc = reader.fromString(xml_fh.read())
doc = parseString(xml_fh.read())
except: except:
xml_fh.close() xml_fh.close()
error("Error while parsing xml") error("Error while parsing xml")
@ -42,10 +45,10 @@ def gen_tunable_conf(doc, file):
file.write("# %s\n" % line) file.write("# %s\n" % line)
tun_name = tun_val = None tun_name = tun_val = None
for (name, value) in node.attributes.items(): for (name, value) in node.attributes.items():
if name[1] == "name": if name == "name":
tun_name = value.value tun_name = value
elif name[1] == "dftval": elif name == "dftval":
tun_val = value.value tun_val = value
if tun_name and tun_val: if tun_name and tun_val:
file.write("%s = %s\n\n" % (tun_name, tun_val)) file.write("%s = %s\n\n" % (tun_name, tun_val))
@ -58,10 +61,10 @@ def gen_module_conf(doc, file):
for node in doc.getElementsByTagName("module"): for node in doc.getElementsByTagName("module"):
mod_name = mod_layer = None mod_name = mod_layer = None
for (name, value) in node.attributes.items(): for (name, value) in node.attributes.items():
if name[1] == "name": if name == "name":
mod_name = value.value mod_name = value
if name[1] == "layer": if name == "layer":
mod_layer = value.value mod_layer = value
if mod_name and mod_layer: if mod_name and mod_layer:
file.write("# Layer: %s\n# Module: %s\n#\n" % (mod_layer,mod_name)) file.write("# Layer: %s\n# Module: %s\n#\n" % (mod_layer,mod_name))
@ -116,13 +119,12 @@ def gen_docs(doc, dir, templatedir):
for node in doc.getElementsByTagName("module"): for node in doc.getElementsByTagName("module"):
mod_name = mod_layer = interface_buf = '' mod_name = mod_layer = interface_buf = ''
for (name, value) in node.attributes.items(): for (name, value) in node.attributes.items():
if name[1] == "name": if name == "name":
mod_name = value.value mod_name = value
if name[1] == "layer": if name == "layer":
mod_layer = value.value mod_layer = value
for desc in node.getElementsByTagName("summary"): for desc in node.getElementsByTagName("summary"):
mod_summary = desc.firstChild.data mod_summary = desc.firstChild.data
if not module_list.has_key(mod_layer): if not module_list.has_key(mod_layer):
module_list[mod_layer] = {} module_list[mod_layer] = {}
@ -171,10 +173,10 @@ def gen_docs(doc, dir, templatedir):
for node in doc.getElementsByTagName("module"): for node in doc.getElementsByTagName("module"):
mod_name = mod_layer = interface_buf = '' mod_name = mod_layer = interface_buf = ''
for (name, value) in node.attributes.items(): for (name, value) in node.attributes.items():
if name[1] == "name": if name == "name":
mod_name = value.value mod_name = value
if name[1] == "layer": if name == "layer":
mod_layer = value.value mod_layer = value
for desc in node.getElementsByTagName("summary"): for desc in node.getElementsByTagName("summary"):
mod_summary = desc.firstChild.data mod_summary = desc.firstChild.data
for interface in node.getElementsByTagName("interface"): for interface in node.getElementsByTagName("interface"):
@ -182,7 +184,7 @@ def gen_docs(doc, dir, templatedir):
interface_secdesc = None interface_secdesc = None
interface_tpl = pyplate.Template(intdata) interface_tpl = pyplate.Template(intdata)
for i,v in interface.attributes.items(): for i,v in interface.attributes.items():
interface_name = v.value interface_name = v
for desc in interface.getElementsByTagName("description"): for desc in interface.getElementsByTagName("description"):
interface_desc = desc.firstChild.data interface_desc = desc.firstChild.data
for desc in interface.getElementsByTagName("securitydesc"): for desc in interface.getElementsByTagName("securitydesc"):
@ -194,10 +196,10 @@ def gen_docs(doc, dir, templatedir):
paramname = None paramname = None
paramopt = "No" paramopt = "No"
for name,val in args.attributes.items(): for name,val in args.attributes.items():
if name[1] == "name": if name == "name":
paramname = val.value paramname = val
if name[1] == "optional": if name == "optional":
if val.value == "true": if val == "true":
paramopt = "yes" paramopt = "yes"
parameter = { "name" : paramname, parameter = { "name" : paramname,
"desc" : paramdesc, "desc" : paramdesc,
@ -247,6 +249,13 @@ def usage():
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")
sys.stdout.write("-T --templates <dir> -- template directory for documents\n") sys.stdout.write("-T --templates <dir> -- template directory for documents\n")
def sort_dict(d):
our_list = d.items()
our_list.sort()
k = {}
for item in our_list:
k[item[0]] = item[1]
return k
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:], "t:m:d:x:T:", ["tunables","modules","docs","xml", "templates"])