def prescrub(self, xml, attrs): # This handles eval tags parser = make_parser() graphnode = rocks.profile.Node("temppost") handler=rocks.profile.Pass1NodeHandler(graphnode,"report-post",{},attrs, eval=1) parser.setContentHandler(handler) for line in xml: parser.feed(line) newxml = handler.getXML() return newxml
def parseNode(self, node, eval=1): if node.name in ["HEAD", "TAIL"]: return nodesPath = [ os.path.join(".", "nodes"), os.path.join("..", "nodes"), os.path.join(".", "site-nodes"), os.path.join("..", "site-nodes"), ] # Find the xml file for each node in the graph. If we # can't find one just complain and abort. xml = [None, None, None] # rocks, extend, replace for dir in nodesPath: if self.os == "sunos": file = os.path.join(dir, "sol_%s.xml" % node.name) if os.path.isfile(file): node.name = "sol_%s" % node.name if not xml[0]: file = os.path.join(dir, "%s.xml" % node.name) if os.path.isfile(file): xml[0] = file if not xml[1]: file = os.path.join(dir, "extend-%s.xml" % node.name) if os.path.isfile(file): xml[1] = file if not xml[2]: file = os.path.join(dir, "replace-%s.xml" % node.name) if os.path.isfile(file): xml[2] = file if not (xml[0] or xml[2]): raise rocks.util.KickstartNodeError, 'cannot find node "%s"' % node.name xmlFiles = [xml[0]] if xml[1]: xmlFiles.append(xml[1]) if xml[2]: xmlFiles = [xml[2]] for xmlFile in xmlFiles: # 1st Pass # - Expand XML Entities # - Expand VAR tags (going away) # - Expand EVAL tags # - Expand INCLUDE/SINCLUDE tag # - Logging for post sections fin = open(xmlFile, "r") parser = make_parser() handler = Pass1NodeHandler(node, xmlFile, self.entities, self.attributes, eval) parser.setContentHandler(handler) parser.feed(handler.getXMLHeader()) linenumber = 0 for line in fin.readlines(): linenumber += 1 # Some of the node files might have the <?xml # document header. Since we are replacing # the XML header with our own (which includes # the entities) we need to skip it. if line.find("<?xml") != -1: continue # Send the XML to stderr for debugging before # we parse it. if os.environ.has_key("ROCKSDEBUG"): sys.stderr.write("[parse1]%s" % line) try: parser.feed(line) except: print "XML parse error in " + "file %s " % xmlFile + "on line %d\n" % linenumber raise fin.close() # 2nd Pass # - Annotate all tags with ROLL attribute # - Annotate all tags with FILE attribute # - Strip off KICKSTART tags # # The second pass is required since EVAL tags can # create their own XML, instead of requiring the # user to annotate we do it for them. parser = make_parser() xml = handler.getXML() handler = Pass2NodeHandler(node, self.attributes) parser.setContentHandler(handler) if os.environ.has_key("ROCKSDEBUG"): sys.stderr.write("[parse2]%s" % xml) parser.feed(xml) # Attach the final XML to the node object so we can # find it again. node.addXML(handler.getXML()) node.addKSText(handler.getKSText())
def parseNode(self, node, eval=True, rcl=None): if node.name in [ 'HEAD', 'TAIL' ]: return nodesPath = [] for dir in self.directories: nodesPath.append(os.path.join(dir, 'nodes')) # Find the xml file for each node in the graph. If we # can't find one just complain and abort. xml = [ None, None, None ] # default, extend, replace for dir in nodesPath: if not xml[0]: file = os.path.join(dir, '%s.xml' % node.name) if os.path.isfile(file): xml[0] = file if not xml[1]: file = os.path.join(dir, 'extend-%s.xml'\ % node.name) if os.path.isfile(file): xml[1] = file if not xml[2]: file = os.path.join(dir, 'replace-%s.xml'\ % node.name) if os.path.isfile(file): xml[2] = file if not (xml[0] or xml[2]): raise stack.util.KickstartNodeError, \ 'cannot find node "%s"' % node.name xmlFiles = [ xml[0] ] if xml[1]: xmlFiles.append(xml[1]) if xml[2]: xmlFiles = [ xml[2] ] for xmlFile in xmlFiles: # 1st Pass # - Expand XML Entities # - Expand VAR tags (going away) # - Expand EVAL tags # - Expand INCLUDE/SINCLUDE tag # - Logging for post sections fin = open(xmlFile, 'r') parser = make_parser() handler = Pass1NodeHandler(node, xmlFile, self.entities, self.attributes, eval, rcl) parser.setContentHandler(handler) parser.feed(handler.getXMLHeader()) linenumber = 0 for line in fin.readlines(): linenumber += 1 # Some of the node files might have the <?xml # document header. Since we are replacing # the XML header with our own (which includes # the entities) we need to skip it. if line.find('<?xml') != -1: continue # Send the XML to stderr for debugging before # we parse it. if os.environ.has_key('STACKDEBUG'): sys.stderr.write('[parse1]%s' % line) try: parser.feed(line) except: print('XML parse error in ' + \ 'file %s ' % xmlFile + \ 'on line %d\n' % linenumber) raise fin.close() # 2nd Pass # - Annotate all tags with ROLL attribute # - Annotate all tags with FILE attribute # - Strip off KICKSTART tags # # The second pass is required since EVAL tags can # create their own XML, instead of requiring the # user to annotate we do it for them. parser = make_parser() xml = handler.getXML() handler = Pass2NodeHandler(node, self.attributes) parser.setContentHandler(handler) if os.environ.has_key('STACKDEBUG'): sys.stderr.write('[parse2]%s' % xml) parser.feed(xml) # Attach the final XML to the node object so we can # find it again. node.addXML(handler.getXML()) node.addKSText(handler.getKSText())
def parseNode(self, node, eval=1): if node.name in ['HEAD', 'TAIL']: return nodesPath = [ os.path.join('.', 'nodes'), os.path.join('..', 'nodes'), os.path.join('.', 'site-nodes'), os.path.join('..', 'site-nodes') ] # Find the xml file for each node in the graph. If we # can't find one just complain and abort. xml = [None, None, None] # rocks, extend, replace for dir in nodesPath: if self.os == 'sunos': file = os.path.join(dir, 'sol_%s.xml'\ % node.name) if os.path.isfile(file): node.name = 'sol_%s' % node.name if not xml[0]: file = os.path.join(dir, '%s.xml' % node.name) if os.path.isfile(file): xml[0] = file if not xml[1]: file = os.path.join(dir, 'extend-%s.xml'\ % node.name) if os.path.isfile(file): xml[1] = file if not xml[2]: file = os.path.join(dir, 'replace-%s.xml'\ % node.name) if os.path.isfile(file): xml[2] = file if not (xml[0] or xml[2]): raise rocks.util.KickstartNodeError, \ 'cannot find node "%s"' % node.name xmlFiles = [xml[0]] if xml[1]: xmlFiles.append(xml[1]) if xml[2]: xmlFiles = [xml[2]] for xmlFile in xmlFiles: # 1st Pass # - Expand XML Entities # - Expand VAR tags (going away) # - Expand EVAL tags # - Expand INCLUDE/SINCLUDE tag # - Logging for post sections fin = open(xmlFile, 'r') parser = make_parser() handler = Pass1NodeHandler(node, xmlFile, self.entities, self.attributes, eval) parser.setContentHandler(handler) parser.feed(handler.getXMLHeader()) linenumber = 0 for line in fin.readlines(): linenumber += 1 # Some of the node files might have the <?xml # document header. Since we are replacing # the XML header with our own (which includes # the entities) we need to skip it. if line.find('<?xml') != -1: continue # Send the XML to stderr for debugging before # we parse it. if os.environ.has_key('ROCKSDEBUG'): sys.stderr.write('[parse1]%s' % line) try: parser.feed(line) except: print 'XML parse error in ' + \ 'file %s ' % xmlFile + \ 'on line %d\n' % linenumber raise fin.close() # 2nd Pass # - Annotate all tags with ROLL attribute # - Annotate all tags with FILE attribute # - Strip off KICKSTART tags # # The second pass is required since EVAL tags can # create their own XML, instead of requiring the # user to annotate we do it for them. parser = make_parser() xml = handler.getXML() handler = Pass2NodeHandler(node, self.attributes) parser.setContentHandler(handler) if os.environ.has_key('ROCKSDEBUG'): sys.stderr.write('[parse2]%s' % xml) parser.feed(xml) # Attach the final XML to the node object so we can # find it again. node.addXML(handler.getXML()) node.addKSText(handler.getKSText())
def parseNode(self, node, eval=1): if node.name in [ 'HEAD', 'TAIL' ]: return nodesPath = [ os.path.join('.', 'nodes'), os.path.join('..', 'nodes'), os.path.join('.', 'site-nodes'), os.path.join('..', 'site-nodes') ] # Find the xml file for each node in the graph. If we # can't find one just complain and abort. xml = [ None, None, None ] # rocks, extend, replace for dir in nodesPath: if not xml[0]: file = os.path.join(dir, '%s.xml' % node.name) if os.path.isfile(file): xml[0] = file if not xml[1]: file = os.path.join(dir, 'extend-%s.xml'\ % node.name) if os.path.isfile(file): xml[1] = file if not xml[2]: file = os.path.join(dir, 'replace-%s.xml'\ % node.name) if os.path.isfile(file): xml[2] = file if not (xml[0] or xml[2]): raise rocks.util.KickstartNodeError, \ 'cannot find node "%s"' % node.name xmlFiles = [ xml[0] ] if xml[1]: xmlFiles.append(xml[1]) if xml[2]: xmlFiles = [ xml[2] ] for xmlFile in xmlFiles: # 1st Pass # - Expand VAR tags # - Expand EVAL tags # - Expand INCLUDE/SINCLUDE tag # - Logging for post sections fin = open(xmlFile, 'r') parser = make_parser() handler = Pass1NodeHandler(node, xmlFile, self.entities, eval) parser.setContentHandler(handler) parser.parse(fin) fin.close() # 2nd Pass # - Annotate all tags with ROLL attribute # - Annotate all tags with FILE attribute # - Strip off KICKSTART tags # # The second pass is required since EVAL tags can # create their own XML, instead of requiring the # user to annotate we do it for them. parser = make_parser() xml = handler.getXML() handler = Pass2NodeHandler(node) parser.setContentHandler(handler) parser.feed(xml) # Attach the final XML to the node object so we can find # it again. node.addXML(handler.getXML()) node.addKSText(handler.getKSText())