def main(argv): """ The XML file is expected to be after the syntax described in xmlcatconf.dtd. """ try: # KeyboardInterrupt # Parse command line flags # -------------------------------------------- optParser = OptionParser( "usage: %prog <URL "\ "test utility> <URL to Test Suite XML file>", version="%prog 0.1" ) (opts, args) = optParser.parse_args(argv) # -------------------------------------------- # Do sanity checks if len(args) < 2: optParser.error("You must supply an URL which specifies the OASIS " \ "XML Catalog test utility, and an URL to the Test Suite file.") if len(args) > 2: optParser.error("It makes no sense to supply more than two URLs.") global testUtility, testSuite testUtility = args[0] testSuite = os.path.abspath(args[1]) if not os.access(testUtility, os.X_OK): sys.stderr.write("The file " + testUtility + " does not exist or have " \ "not execute permissions.\n") sys.exit(1) # -------------------------------------------- # Open the file impl = getDOMImplementation() try: sourceDocument = parse(testSuite) except ExpatError, e: sys.stderr.write("Specified file is not " + str(e) + '\n') sys.exit(1) global resultDocument resultDocument = impl.createDocument( "", "CatalogTestResults", DocumentType("CatalogTestResults")) resDocElement = resultDocument.documentElement children = sourceDocument.documentElement.childNodes for e in children: if e.nodeType == Node.ELEMENT_NODE: resDocElement.appendChild(parseTestCases(e)) print resultDocument.toprettyxml()
def to_xml(self, encoding="UTF-8", pretty=True): dom = Document() dom.version = "1.0" dom.encoding = "UTF-8" doc_type = DocumentType("plist") doc_type.publicId = "-//Apple Computer//DTD PLIST 1.0//EN" doc_type.systemId = "http://www.apple.com/DTDs/PropertyList-1.0.dtd" dom.appendChild(doc_type) plist_node = dom.createElement("plist") plist_node.setAttribute("version", "1.0") dom.appendChild(plist_node) plist_root = dom.createElement("dict") plist_node.appendChild(plist_root) temp_pairs = [(self, plist_root)] while temp_pairs: data, root = temp_pairs.pop(0) if isinstance(data, dict): for k, v in data.items(): k_node = dom.createElement("key") text_node = dom.createTextNode(k) k_node.appendChild(text_node) root.appendChild(k_node) if isinstance(v, dict): v_node = dom.createElement("dict") temp_pairs.append((v, v_node)) elif isinstance(v, list): v_node = dom.createElement("array") temp_pairs.append((v, v_node)) else: v_node = self._to_dom_node(v, dom) root.appendChild(v_node) elif isinstance(data, list): for v in data: if isinstance(v, dict): v_node = dom.createElement("dict") temp_pairs.append((v, v_node)) elif isinstance(v, list): v_node = dom.createElement("array") temp_pairs.append((v, v_node)) else: v_node = self._to_dom_node(v, dom) root.appendChild(v_node) else: data_node = self._to_dom_node(data, dom) root.appendChild(data_node) if pretty: xml_content = dom.toprettyxml(encoding=encoding) else: xml_content = dom.toxml(encoding=encoding) return xml_content
def toXml(self, selected=None): doc = Document() doctype = DocumentType("Tags") doctype.systemId = "matroskatags.dtd" tags = Element("Tags") for item in (selected or self): tags.appendChild(item.toXml()) doc.appendChild(doctype) doc.appendChild(tags) return doc
def toXml(self, selected=None): doc = Document() doctype = DocumentType("Chapters") doctype.systemId = "matroskachapters.dtd" editions = Element("Chapters") for item in (selected or self): editions.appendChild(item.toXml()) doc.appendChild(doctype) doc.appendChild(editions) return doc
def __makeBookkeepingXML(self, bkLFNs, logFilePath): ''' Bookkeeping xml looks like this: <Job ConfigName="" ConfigVersion="" Date="" Time=""> <TypedParameter Name="" Type="" Value=""/> ... <InputFile Name=""/> ... <OutputFile Name="" TypeName="" TypeVersion=""> <Parameter Name="" Value=""/> ... <Replica Location="" Name=""/> .... </OutputFile> ... <SimulationCondition> <Parameter Name="" Value=""/> </SimulationCondition> </Job> ''' # Generate XML document doc = Document() docType = DocumentType("Job") docType.systemId = "book.dtd" doc.appendChild(docType) # Generate JobNode doc, jobNode = self.__generateJobNode(doc) # Generate TypedParams jobNode = self.__generateTypedParams(jobNode) # Generate InputFiles jobNode = self.__generateInputFiles(jobNode, bkLFNs) # Generate OutputFiles jobNode = self.__generateOutputFiles(jobNode, bkLFNs, logFilePath) # Generate SimulationConditions jobNode = self.__generateSimulationCondition(jobNode) prettyXMLDoc = doc.toprettyxml(indent=" ", encoding="ISO-8859-1") # horrible, necessary hack! prettyXMLDoc = prettyXMLDoc.replace('\'book.dtd\'', '\"book.dtd\"') return prettyXMLDoc
def toXHTML(self): """ Print a message into XHTML+RDFa format """ #root nodes doc = getDOMImplementation().createDocument(None, 'html', None) doctype = DocumentType("html") doctype.publicId = "-//W3C//DTD XHTML+RDFa 1.0//EN" doctype.systemId = "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd" doc.doctype = doctype root = doc.documentElement root.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml') root.setAttribute('xmlns:sioc', str(SIOC)) root.setAttribute('xmlns:foaf', str(FOAF)) root.setAttribute('xmlns:dc', str(DC)) root.setAttribute('xmlns:dct', str(DCT)) root.setAttribute('xmlns:mvcb', str(MVCB)) root.setAttribute('xmlns:xsd', str(XSD)) head = doc.createElement('head') root.appendChild(head) head.setAttribute('profile', 'http://www.w3.org/2003/g/data-view') link = doc.createElement('link') link.setAttribute('rel', 'transformation') link.setAttribute( 'href', 'http://www-sop.inria.fr/acacia/soft/RDFa2RDFXML.xsl') head.appendChild(link) link = doc.createElement('link') link.setAttribute('rel', 'meta') link.setAttribute('type', 'application/rdf+xml') link.setAttribute('title', 'SIOC') link.setAttribute('href', self.getRdfUrl()) head.appendChild(link) link = doc.createElement('link') link.setAttribute('rel', 'stylesheet') link.setAttribute('type', 'text/css') link.setAttribute('href', self.config.get('base') + 'swaml.css') head.appendChild(link) title = doc.createElement('title') title.appendChild(doc.createTextNode(self.getSubject())) head.appendChild(title) #body body = doc.createElement('body') body.setAttribute('typeof', 'foaf:Document') body.setAttribute('about', self.getXhtmlUrl()) root.appendChild(body) p = doc.createElement('p') span = doc.createElement('span') span.setAttribute('rel', 'foaf:primaryTopic') span.setAttribute('href', self.getUri()) body.appendChild(p) p.appendChild(span) #post div div = doc.createElement('div') body.appendChild(div) div.setAttribute('typeof', 'sioc:Post') div.setAttribute('about', self.getUri()) #post fields try: h1 = doc.createElement('h1') div.appendChild(h1) h1.setAttribute('property', 'dc:title') h1.appendChild(doc.createTextNode(self.getSubject())) p = doc.createElement('p') div.appendChild(p) strong = doc.createElement('strong') p.appendChild(strong) strong.appendChild(doc.createTextNode('From: ')) a = doc.createElement('a') a.setAttribute('rel', 'sioc:has_creator') a.setAttribute('href', self.getSender().getUri()) a.appendChild(doc.createTextNode(self.getSender().getName())) p.appendChild(a) p = doc.createElement('p') div.appendChild(p) strong = doc.createElement('strong') p.appendChild(strong) strong.appendChild(doc.createTextNode('To: ')) a = doc.createElement('a') a.setAttribute('rel', 'sioc:has_container') a.setAttribute('href', self.config.get('base') + 'forum') if (len(self.config.get('title')) > 0): a.appendChild(doc.createTextNode(self.config.get('title'))) else: a.appendChild( doc.createTextNode(self.config.get('base') + 'forum')) p.appendChild(a) p = doc.createElement('p') div.appendChild(p) strong = doc.createElement('strong') p.appendChild(strong) strong.appendChild(doc.createTextNode('Date: ')) span = doc.createElement('span') span.setAttribute('property', 'dct:created') span.setAttribute('datatype', 'xsd:dateTime') span.appendChild(doc.createTextNode(self.getDate())) p.appendChild(span) #p = doc.createElement('p') #div.appendChild(p) #strong = doc.createElement('strong') #p.appendChild(strong) #strong.appendChild(doc.createTextNode('Message-Id: ')) #span = doc.createElement('span') #span.setAttribute('property', 'sioc:id') #span.appendChild(doc.createTextNode(self.getSwamlId())) #p.appendChild(span) pre = doc.createElement('pre') div.appendChild(pre) pre.setAttribute('property', 'sioc:content') pre.appendChild(doc.createTextNode( self.getBody())) #FIXME: parse URLs p = doc.createElement('p') div.appendChild(p) p.appendChild(doc.createTextNode('URI: ')) a = doc.createElement('a') a.setAttribute('href', self.getUri()) a.appendChild(doc.createTextNode(self.getUri())) p.appendChild(a) p = doc.createElement('p') div.appendChild(p) p.appendChild(doc.createTextNode('Link: ')) a = doc.createElement('a') a.setAttribute('rel', 'sioc:link') a.setAttribute('href', self.getXhtmlUrl()) a.appendChild(doc.createTextNode(self.getXhtmlUrl())) p.appendChild(a) parent = self.getParent() if (parent != None): p = doc.createElement('p') div.appendChild(p) p.appendChild(doc.createTextNode('Reply of: ')) a = doc.createElement('a') a.setAttribute('rel', 'sioc:reply_of') a.setAttribute('href', parent) a.appendChild(doc.createTextNode(parent)) p.appendChild(a) if (len(self.childs) > 0): for child in self.childs: p = doc.createElement('p') div.appendChild(p) p.appendChild(doc.createTextNode('Has reply: ')) a = doc.createElement('a') a.setAttribute('rel', 'sioc:has_reply') a.setAttribute('href', child) a.appendChild(doc.createTextNode(child)) p.appendChild(a) previous = self.getPreviousByDate() if (previous != None): p = doc.createElement('p') div.appendChild(p) p.appendChild(doc.createTextNode('Previous by Date: ')) a = doc.createElement('a') a.setAttribute('rel', 'sioc:previous_by_date') a.setAttribute('href', previous) a.appendChild(doc.createTextNode(previous)) p.appendChild(a) next = self.getNextByDate() if (next != None): p = doc.createElement('p') div.appendChild(p) p.appendChild(doc.createTextNode('Next by Date: ')) a = doc.createElement('a') a.setAttribute('rel', 'sioc:next_by_date') a.setAttribute('href', next) a.appendChild(doc.createTextNode(next)) p.appendChild(a) except Exception, detail: print 'Error exporting to XHTML message ' + str( self.getId()) + ': ' + str(detail)
if not 'efmenu' in doc_map: print "\nerror: No EF menu supplied\n" usage() sys.exit(1) # start the merging l2ChainList = doc_map[ 'l2menu' ].getElementsByTagName( "CHAIN_LIST" )[0] efChainList = doc_map[ 'efmenu' ].getElementsByTagName( "CHAIN_LIST" )[0] l2SeqList = doc_map[ 'l2menu' ].getElementsByTagName( "SEQUENCE_LIST" )[0] efSeqList = doc_map[ 'efmenu' ].getElementsByTagName( "SEQUENCE_LIST" )[0] doc = Document() doctype = DocumentType( "HLT_MENU" ) #doctype.systemId = "hlt_menu.dtd" doc.appendChild( doctype ); hlt_menu = doc.createElement( "HLT_MENU" ) if name == 'XML': efmenu_el = doc_map[ 'efmenu' ].getElementsByTagName( "HLT_MENU" )[0] name = efmenu_el.getAttribute("menu_name") prescale_set_name = efmenu_el.getAttribute("prescale_set_name") hlt_menu.setAttribute( "prescale_set_name", prescale_set_name ) hlt_menu.setAttribute( "menu_name", name ) doc.appendChild( hlt_menu ) # merge sequences processedSeq = [] seqList = doc.createElement("SEQUENCE_LIST") hlt_menu.appendChild( seqList )
def CreateXMLFile(runlist, options, origQuery, datapath, xmlfname, xmllabel, svnversion='Unknown'): """ """ with timer('create RunStreamAndNeventsList'): # show number of events per stream per run ? ShowNumberOfEventsPerStreamPerRun = False ShowNumberOfEventsPerStreamSummary = True # find streams runstreamevents, runnrliststr = CreateRunStreamAndNeventsList( runlist) # { runnr: { stream: [(LUMIBLOCKNR, NREVENTS)] } } with timer('prepare document'): #################################### ## create XML file of GRL #################################### doc = Document() docType = DocumentType('LumiRangeCollection') docType.systemId = 'http://atlas-runquery.cern.ch/LumiRangeCollection.dtd' doc.appendChild(docType) # number of comments txt = ' Good-runs-list created by %s on %s ' % ( sys.argv[0].split('/')[-1], str(datetime.datetime.now())) doc.appendChild(doc.createComment(txt)) # root element lrc = doc.createElement('LumiRangeCollection') doc.appendChild(lrc) # NamedLumiRange namedLR = doc.createElement('NamedLumiRange') lrc.appendChild(namedLR) # name of NamedLumiRange namedLR.appendChild(TextElement('Name', xmllabel, doc)) # version of NamedLumiRange namedLR.appendChild(TextElement('Version', '2.1', doc)) # metadata of NamedLumiRange metadata = { 'Query': origQuery.split('/')[0], 'RQTSVNVersion': svnversion, 'RunList': runnrliststr } for md in metadata: mdelm = TextElement('Metadata', metadata[md], doc) mdelm.setAttribute('Name', md) namedLR.appendChild(mdelm) with timer('ShowNumberOfEventsPerStreamSummary'): if ShowNumberOfEventsPerStreamSummary: strsummdelm = doc.createElement('Metadata') strsummdelm.setAttribute('Name', 'StreamListInfo') namedLR.appendChild(strsummdelm) # lumiblock collections of NamedLumiRange streams_sum = {} streams_byrun = {} with timer('Loop over all runs'): for run in runlist: lbc = doc.createElement('LumiBlockCollection') # run number runnrelm = TextElement('Run', str(run.runNr), doc) if len(run.stats['SMK']['random']) == 2: (rd0, rd1) = run.stats['SMK']['random'][0:2] # protect against missing information if rd0 == 'n.a.': rd0 = 0 if rd1 == 'n.a.': rd1 = 0 runnrelm.setAttribute('PrescaleRD0', 0x1 << (3 + rd0)) runnrelm.setAttribute('PrescaleRD1', 0x1 << (3 + rd1)) else: (rd0, rd1, rd2, rd3) = run.stats['SMK']['random'][0:4] # protect against missing information if rd0 == 'n.a.': rd0 = 0 if rd1 == 'n.a.': rd1 = 0 if rd2 == 'n.a.': rd2 = 0 if rd3 == 'n.a.': rd3 = 0 runnrelm.setAttribute('Cut0', rd0) runnrelm.setAttribute('Cut1', rd1) runnrelm.setAttribute('Cut2', rd2) runnrelm.setAttribute('Cut3', rd3) lbc.appendChild(runnrelm) # streams (initialisation) streams = {} streams_byrun[run.runNr] = streams if runstreamevents.has_key( run.runNr ): # protection in case the run does not have any stream for stream in runstreamevents[run.runNr].keys(): if 'physics_' == stream[:8]: streams[stream] = [0, 0] # only for physics streams if not streams_sum.has_key(stream): streams_sum[stream] = [0, 0] # total number of events in stream for (nlb, nev) in runstreamevents[run.runNr][stream]: streams[stream][0] += nev # lumiblock ranges for lbrange in run.data.getLBRanges(activeOnly=True): lbrelm = TextElement('LBRange', '', doc) lbrelm.setAttribute('Start', lbrange[1]) lbrelm.setAttribute('End', lbrange[2] - 1) lbc.appendChild(lbrelm) # count nevents in streams if runstreamevents.has_key( run.runNr ): # protection in case the run does not have any stream for stream, lbnevts in runstreamevents[run.runNr].items(): if 'physics_' == stream[:8]: for (nlb, nev) in lbnevts: if nlb >= lbrange[1] and nlb < lbrange[2]: streams[stream][1] += nev # append stream element s = streams.keys() s.sort() strselm = doc.createElement('StreamsInRun') for stream in s: nevts = streams[stream] if ShowNumberOfEventsPerStreamPerRun: strelm = TextElement('Stream', '', doc) strelm.setAttribute('Name', stream) strelm.setAttribute('TotalNumOfEvents', nevts[0]) strelm.setAttribute('NumOfSelectedEvents', nevts[1]) strselm.appendChild(strelm) eff = 0 if nevts[0] > 0: eff = nevts[1] / float(nevts[0]) * 100.0 # collect total number of events streams_sum[stream][0] += nevts[0] streams_sum[stream][1] += nevts[1] # append streams if ShowNumberOfEventsPerStreamPerRun: lbc.appendChild(strselm) # append LumiBlickCollection namedLR.appendChild(lbc) with timer('Streams'): for stream in sorted(streams_sum.keys()): nevts = streams_sum[stream] if ShowNumberOfEventsPerStreamSummary: strelm = TextElement('Stream', '', doc) strelm.setAttribute('Name', stream) strelm.setAttribute('TotalNumOfEvents', nevts[0]) strelm.setAttribute('NumOfSelectedEvents', nevts[1]) strsummdelm.appendChild(strelm) with timer('Save GRL'): filename = '%s/%s' % (datapath, xmlfname) #print "Writing",filename xmlfile = open(filename, mode="w") xmlfile.write(doc.toprettyxml(' ')) xmlfile.close() with timer('Create HTML'): #################################### ## create HTML #################################### # provide also pretty html text output htmltext = '' hspace = ' ' htmltext += '<table style="width: auto; border: 0px solid; border-width: margin: 0 0 0 0; 0px; border-spacing: 0px; border-collapse: separate; padding: 0px;" font-family: sans-serif; font-size: 85%%">\n' htmltext += '<tr><td colspan="2"><b><font color="#999999">' + txt.strip( ) + '</font></b></td></tr>\n' htmltext += '<tr><td style="vertical-align:top">SVN Version: </td><td> ' + svnversion + '</td></tr>\n' htmltext += '<tr><td style="vertical-align:top">Query string:</td><td><b>' + origQuery.split( '/')[0] + '</b></td></tr>\n' htmltext += '<tr><td style="vertical-align:top">Run list:</td><td>' + runnrliststr + '</td></tr>\n' htmltext += '</table>' htmltext += '<hr color="#000000" size=1><font color="#777777">\n' htmltext += '<table style="width: auto; border: 0px solid; border-width: margin: 0 0 0 0; 0px; border-spacing: 0px; border-collapse: separate; padding: 0px;" font-family: sans-serif; font-size: 90%%">\n' # lumiblock collections of NamedLumiRange for run in runlist: # run number htmltext += '<tr><td style="text-align:left;height:25px;vertical-align:bottom">Run <b>%i</b>:</td><td></td></tr>\n' % run.runNr # lumiblock ranges for lbrange in run.data.getLBRanges(activeOnly=True): htmltext += '<tr><td></td><td style="text-align:left">LB range: [%5i-%5i]</td></tr>\n' % ( lbrange[1], lbrange[2] - 1) # append stream element htmltext += '<tr><td></td><td style="text-align:left"></td></tr>' htmltext += '<tr><td></td><td style="text-align:left"><table style="width: auto; border: 0px solid; border-width: margin: 0 0 0 0; 0px; border-spacing: 0px; border-collapse: separate; padding: 0px;font-family: sans-serif; font-size: 90%"><tr><td>Stream name</td><td>#Events total</td><td> #Events selected</td><td> Sel. fraction (%)</td></tr>\n' streams = streams_byrun[run.runNr] for stream in sorted(streams.keys()): nevts = streams[stream] eff = (nevts[1] / float(nevts[0]) * 100.0) if (nevts[0] > 0) else 0 htmltext += '<tr><td style="text-align:left"><i>%s</i></td><td style="text-align:right">%s</td><td style="text-align:right">%s</td><td style="text-align:right">%.4g</td></tr>\n' % ( stream, prettyNumber(nevts[0]), prettyNumber( nevts[1]), eff) htmltext += '</table></td></tr>\n' # append stream element htmltext += '</table>' htmltext += '<hr color="#000000" size=1><font color="#777777">\n' htmltext += '<b>Stream summary for all selected runs:</b><br>\n' htmltext += '<table style="width: auto; border: 0px solid; border-width: margin: 0 0 0 0; 0px; border-spacing: 0px; border-collapse: separate; padding: 0px;font-family: sans-serif; font-size: 95%"><tr><td>Stream name</td><td>#Events total</td><td> #Events selected</td><td> Sel. fraction (%)</td></tr>\n' for stream in sorted(streams_sum.keys()): nevts = streams_sum[stream] eff = 0 if nevts[0] > 0: eff = nevts[1] / float(nevts[0]) * 100.0 htmltext += '<tr><td style="text-align:left"><i>%s</i></td><td style="text-align:right">%s</td><td style="text-align:right">%s</td><td style="text-align:right">%.4g</td></tr>\n' % ( stream, prettyNumber(nevts[0]), prettyNumber(nevts[1]), eff) htmltext += '</table>\n' #print """======================================================== #%r #=========================================================== #""" % htmltext # provide also text output return htmltext
def createSignatureDoc(chains, signatures, streamtags, triggerbits, triggergroups): rel13_tag = True if len(streamtags) == 0 and len(triggerbits) == 0: rel13_tag = False # create dom document doc = Document() doctype = DocumentType("CHAIN_LIST") doctype.systemId = "chainlist.dtd" doc.appendChild(doctype) # comment fields C = [] C.append( doc.createComment("xml script created %s on %s" % (time.asctime(), socket.gethostname()))) for c in C: doc.appendChild(c) # chain list firstChain = dict(zip(get_chain_record("keys"), chains[0])) chainList = doc.createElement("CHAIN_LIST") chainList.setAttribute("hlt_master_table.name", firstChain["menu.name"]) chainList.setAttribute("hlt_master_table.version", str(firstChain["menu.version"])) chainList.setAttribute("hlt_trigger_menu.name", firstChain["menu.name"]) chainList.setAttribute("hlt_trigger_menu.version", str(firstChain["menu.name"])) chainList.setAttribute("hlt_prescale_set.name", firstChain["pres.name"]) chainList.setAttribute("hlt_prescale_set.version", str(firstChain["pres.version"])) doc.appendChild(chainList) # chains prevLevel = "" prevChainCounter = 0 prevSigCounter = 0 prevTE = "" streamTagRecords = [] isFirstChain = True streamtagDict = {} for record in streamtags: stream = dict(zip(get_streamtag_record("keys"), record)) Lvl_ChCount = "%s_%i" % (str( stream["chain.level"]), int(stream["chain.counter"])) streamtag = doc.createElement("STREAMTAG") streamtag.setAttribute("obeyLB", str(stream["stream.obeylb"])) streamtag.setAttribute("prescale", str(stream["stream.pres"])) streamtag.setAttribute("stream", str(stream["stream.name"])) streamtag.setAttribute("type", str(stream["stream.type"])) if not Lvl_ChCount in streamtagDict: streamtagDict[Lvl_ChCount] = [] streamtagDict[Lvl_ChCount].append(streamtag) triggerbitDict = {} for record in triggerbits: triggerbit = dict(zip(get_triggerbit_record("keys"), record)) Lvl_ChCount = "%s_%i" % (str( triggerbit["chain.level"]), int(triggerbit["chain.counter"])) triggertype = doc.createElement("TRIGGERTYPE") triggertype.setAttribute("bit", str(triggerbit["triggerbit"])) if not Lvl_ChCount in triggerbitDict: triggerbitDict[Lvl_ChCount] = [] triggerbitDict[Lvl_ChCount].append(triggertype) triggergroupDict = {} for record in triggergroups: print record group = dict(zip(get_triggergroup_record("keys"), record)) Lvl_ChCount = "%s_%i" % (str( group["chain.level"]), int(group["chain.counter"])) if not Lvl_ChCount in triggergroupDict: triggergroupDict[Lvl_ChCount] = [] triggergroup = doc.createElement("GROUP") triggergroup.setAttribute("name", str(group["group.name"])) triggergroupDict[Lvl_ChCount].append(triggergroup) signatureDict = {} for record in signatures: signature = dict(zip(get_signature_record("keys"), record)) Lvl_ChCount = "%s_%i" % (str( signature["chain.level"]), int(signature["chain.counter"])) if not Lvl_ChCount in signatureDict: signatureDict[Lvl_ChCount] = {} if not signature["sign.counter"] in signatureDict[Lvl_ChCount]: sig = doc.createElement("SIGNATURE") sig.setAttribute("signature_counter", str(signature["sign.counter"])) sig.setAttribute("logic", str(signature["sign.logic"])) signatureDict[Lvl_ChCount][signature["sign.counter"]] = sig # trigger elements in signature te = doc.createElement("TRIGGERELEMENT") te.setAttribute("te_name", signature["te.name"]) signatureDict[Lvl_ChCount][signature["sign.counter"]].appendChild(te) # chains for record in chains: chain = dict(zip(get_chain_record("keys"), record)) Lvl_ChCount = "%s_%i" % (str( chain["chain.level"]), int(chain["chain.counter"])) ch = doc.createElement("CHAIN") chainList.appendChild(ch) ch.setAttribute("chain_name", chain["chain.name"]) ch.setAttribute("chain_counter", "%i" % chain["chain.counter"]) ch.setAttribute("lower_chain_name", chain["chain.lowname"]) ch.setAttribute("level", chain["chain.level"]) ch.setAttribute("prescale", "%i" % chain["chain.pres"]) ch.setAttribute("pass_through", "%i" % chain["chain.pass"]) if rel13_tag: streamtagList = doc.createElement("STREAMTAG_LIST") ch.appendChild(streamtagList) if not Lvl_ChCount in streamtagDict: print "*** error: chain %s in level %s has no streamtag defined" \ % ( str(signature["chain.name"]), str(signature["chain.level"]) ) print streamtagDict.keys() sys.exit(1) else: for streamtag in streamtagDict[Lvl_ChCount]: streamtagList.appendChild(streamtag) triggertypeList = doc.createElement("TRIGGERTYPE_LIST") ch.appendChild(triggertypeList) if not Lvl_ChCount in triggerbitDict: print "*** error: chain %s in level %s has no triggertype defined" \ % ( str(signature["chain.name"]), str(signature["chain.level"]) ) print triggerbitDict.keys() sys.exit(1) else: for triggertype in triggerbitDict[Lvl_ChCount]: triggertypeList.appendChild(triggertype) triggergroupList = doc.createElement("GROUP_LIST") ch.appendChild(triggergroupList) if Lvl_ChCount in triggergroupDict: for triggergroup in triggergroupDict[Lvl_ChCount]: triggergroupList.appendChild(triggergroup) # signatures in chain sigList = doc.createElement("SIGNATURE_LIST") ch.appendChild(sigList) if Lvl_ChCount in signatureDict: sigInChainDict = signatureDict[Lvl_ChCount] sigCounters = sigInChainDict.keys() sigCounters.sort() for sigC in sigCounters: sigList.appendChild(sigInChainDict[sigC]) return doc
def createSequenceDoc(sequences): # create dom document doc = Document() # comment fields C = [] C.append( doc.createComment("xml script created %s on %s" % (time.asctime(), socket.gethostname()))) for c in C: doc.appendChild(c) # document type doctype = DocumentType("SEQUENCE_LIST") doctype.systemId = "sequencelistnewformat.dtd" doc.appendChild(doctype) # sequence list seqList = doc.createElement("SEQUENCE_LIST") seqList.setAttribute("hlt_setup.name", "dummy") seqList.setAttribute("hlt_setup.version", "%i" % 1) doc.appendChild(seqList) # sequences # algorithms algoDict = {} for record in sequences: sequence = dict(zip(get_sequence_record("keys"), record)) if sequence["te.inp.counter"] > 1: continue algSpec = "%s/%s" % (sequence["cp.name"], sequence["cp.alias"]) if not sequence["te.name"] in algoDict: algoDict[sequence["te.name"]] = {} algoDict[sequence["te.name"]][sequence["cp.counter"]] = algSpec # input TEs inpTEdict = {} for record in sequences: sequence = dict(zip(get_sequence_record("keys"), record)) outTE = str(sequence["te.name"]) # determines the sequence if sequence["te.inp.type"] == "input": inpTECount = int(sequence["te.inp.counter"]) else: inpTECount = "topo" if not outTE in inpTEdict: inpTEdict[outTE] = {} if inpTECount in inpTEdict[outTE]: if inpTEdict[outTE][inpTECount] != sequence["te.inp.name"]: print "*** error: at position %s two different input TEs '%s' and '%s' were encountered => abort ***" \ % (str(inpTECount),sequence["te.inp.name"],inpTEdict[outTE][inpTECount]) sys.exit(1) inpTEdict[outTE][inpTECount] = sequence["te.inp.name"] # put the SEQUENCE together for outTE in algoDict: thisTEsInpTEs = inpTEdict[outTE] hasTopoStartFrom = "topo" in thisTEsInpTEs counters = thisTEsInpTEs.keys() if hasTopoStartFrom: counters.remove("topo") counters.sort() inpTEStringDict = inpTEdict[outTE][counters[0]] for c in counters[1:]: inpTEStringDict += " " + inpTEdict[outTE][c] thisTEsAlgs = algoDict[outTE] algCounters = thisTEsAlgs.keys() algCounters.sort() algoString = " ".join([thisTEsAlgs[x] for x in algCounters]) seq = doc.createElement("SEQUENCE") seq.setAttribute("input", inpTEStringDict) if hasTopoStartFrom: seq.setAttribute("topo_start_from", thisTEsInpTEs["topo"]) seq.setAttribute("algorithm", algoString) seq.setAttribute("output", outTE) seqList.appendChild(seq) return doc