class Parser: def __init__(self, qxml): self.qxml = qxml self.nodelist = NodeList() def parse(self): return self.handle_data() def handle_data(self): dom = xml.dom.minidom.parseString(self.qxml) nodes = dom.getElementsByTagName("Node") return self.handle_nodes(nodes) def handle_nodes(self, nodes): for node in nodes: self.nodelist.add(self.handle_node(node)) return self.nodelist def handle_node(self, node): name = StringParser(node, "name").parse() n = Node(name) n.procs = IntParser(node, "np", default=0).parse() n.gpus = IntParser(node, "gpus", default=0).parse() n.properties = StringParser(node, "properties").parse() n.ntype = StringParser(node, "ntype").parse() n.state = StateParser(node, "state").parse() n.jobs, n.slots = JobParser(node, "jobs").parse() n.note = StringParser(node, "note", default='').parse() status = StatusParser(node, "status").parse() n.from_hash(status) return n
def __init__(self, qxml): self.qxml = qxml self.nodelist = NodeList()