def digest_rule_file(file, io): rules = [] logfile_versions = [] if isinstance(file, url_directory.BasePath): io.ReportStatus("Reading rule file: " + file.PathString()) else: io.ReportStatus("Reading rule file: " + file) d = xml_tree.xml_to_tree(file) if string.lower(d.children[0].name) != "rules": raise BadRuleFile, "Toplevel tag must be RULES" for child in d.children[0].children: pre = None post = None if (not isinstance(child, Tag)) or \ (string.lower(child.name) not in ["gc_log_version", "rule", "or"]): io.ReportStatus("Ignoring %s element" % child.__class__.__name__) elif string.lower(child.name) == "gc_log_version": if isinstance(child.children[0], Data): logfile_versions.append(child.children[0].data) elif string.lower(child.name) == "or": rules.append(digest_real_rules(child.children)) else: rules.append(digest_real_rules([child])) io.ReportStatus("...read.") return RuleBaseInstance(d, rules, logfile_versions)
def LoadLandmarks(f): d = xml_tree.xml_to_tree(f) if string.lower(d.children[0].name) != "landmarks": raise "BadFile", "Toplevel tag must be LANDMARKS" for child in d.children[0].children: if (not isinstance(child, Tag)) or \ (string.lower(child.name) not in ["data", "event"]): print "Ignoring %s element" % child.__class__.__name__ continue elif string.lower(child.name) == "data": parent_class = "InterestingData" else: parent_class = "InterestingEvent" for pair_child in child.children: if (not isinstance(child, Tag)) or \ (string.lower(child.name) != "pair"): raise "BadFile", "Children of DATA and EVENT must be PAIR"
def xml_to_formattable_tree(file): return xml_tree.xml_to_tree(file, {"XMLDocument": FormattableXMLDocument, "Tag": FormattableTag})