3 ExtracAppInfoFromXML [-sapc] file 5 file file from where to read a RCMS configuration 6 -s list application servers found in the XML file 7 -p list the ports used found in the XML file 8 -a list the names of the applications configured in the XML file 9 -c list the cfg (eg dqmfu09-1_cfg.py) files 11 The default behavior is to present a table organized in the following way 12 SERVER PORT CFG_FILE APP_NAME 13 which is equivalent to using -sapc 15 The options selected and their order will affect teeh fields shown and their 16 respective sorting. eg. 17 -sa will only show SERVER and APP_NAME and will sort first by SERVER and 20 OUTPUT is always unique in a per row bases 24 from xml.dom
import minidom
34 print "[%d-%d-%d]"%(l,bn,head.nodeType)+tabs+
"+++++>"+head.tagName
35 except AttributeError
as e:
36 print "[%d-%d-%d]"%(l,bn,head.nodeType)+tabs+
"+++++>"+
str(e)
37 print "[%d-%d-%d-v]"%(l,bn,head.nodeType)+tabs+
"."+ (head.nodeValue
or "None")
39 for katt,vatt
in head.attributes.items():
40 if katt!=
"environmentString":
41 print tabs+
"%s=%s"%(katt,vatt)
43 print tabs+
"%s= 'Some Stuff'"%(katt,)
47 for node
in head.childNodes:
53 for item
in head.childNodes:
54 if item.nodeType == 3:
59 for item
in head.childNodes[1:]:
60 if item.nodeType == 3:
61 firstborne.nodeValue+=item.nodeValue
66 """Parses information that's XML format from value to the Docuemnt tree""" 68 if head.firstChild.nodeValue:
69 newNode=minidom.parseString(head.firstChild.nodeValue)
70 for node
in newNode.childNodes:
71 head.appendChild(node.cloneNode(
True))
75 """it searches for the line containing the string consumerName, usually 76 found as a property of the process, and returns the set value found. 79 process.EventStreamHttpReader.consumerName = 'EcalEndcap DQM Consumer' 81 EcalEndcap DQM Consumer 85 consumer = f.readline()
88 consumer=consumer.strip()
89 if "consumerName" in consumer:
90 name=consumer[consumer.index(
"'")+1:consumer.index(
"'",consumer.index(
"'")+1)]
92 consumer = f.readline()
95 sys.stderr.write(
"WARNING: Unable to open file: " + filename +
" from <configFile> section of XML\n")
96 name =
"CONFIG FILE IS M.I.A" 100 """it searches for the line containing the string consumerName, usually 101 found as a property of the process, and returns the set value found. 104 process = cms.Process ("ECALDQM") 111 sys.stderr.write(
"Unable to open file: " + filename +
" from <configFile> section of XML\n")
113 consumer = f.readline()
116 consumer=consumer.strip()
117 if "cms.Process(" in consumer:
118 name=consumer[consumer.index(
"(")+2:consumer.index(
")")-1]
120 consumer = f.readline()
126 branch=branch1[:len(branch1)]
128 for item
in range(len(nodeList)):
129 vals=[v
for (k,v)
in nodeList[idx].attributes.items()]
130 if branch[0]
not in vals:
135 elif len(branch1)==0:
145 key=
min(order.keys())
149 lista=xmldoc.getElementsByTagName(
"XdaqExecutive")
152 table[item.attributes[
"hostname"].value]=
"" 153 for item
in table.keys():
154 table[item]=
fillTable(order.copy(),branch + [item])
156 lista=xmldoc.getElementsByTagName(
"XdaqExecutive")
159 pset=item.getElementsByTagName(
"parameterSet")
161 arch=pset[0].firstChild.nodeValue[5:]
165 App=item.getElementsByTagName(
"xc:Application")
166 table[App[0].attributes[
"class"].value]=
"" 167 for item
in table.keys():
168 table[item]=
fillTable(order.copy(),branch)
170 lista=xmldoc.getElementsByTagName(
"XdaqExecutive")
173 table[item.attributes[
"port"].value]=
"" 174 for item
in table.keys():
175 table[item]=
fillTable(order.copy(),branch + [item])
177 lista=xmldoc.getElementsByTagName(
"XdaqExecutive")
180 pset=item.getElementsByTagName(
"parameterSet")
182 table[
"No additional file"]=
"" 184 table[pset[0].firstChild.nodeValue]=
"" 185 for item
in table.keys():
186 table[item]=
fillTable(order.copy(),branch)
192 """table => {s:{p:{c:{a:{}}}}}""" 194 for (server,ports)
in table.items():
195 for (port,configfiles)
in ports.items():
196 for (configfile,appnames)
in configfiles.items():
197 for appname
in appnames.keys():
199 for col
in order.values():
205 line.append(configfile)
216 for col
in range(numcols):
219 for col
in range(numcols):
220 if len(line[col])>maxs[col]:
221 maxs[col]=len(line[col])
224 for col
in range(numcols):
225 pline+=line[col].ljust(maxs[col]+2)
232 """ getAppInfo(XMLf,s=0,a=2,p=1,c=3) takes the file name of a valid RCMS 233 configuration and 4 variables that represent which fields are desired 236 It returns a touple containing a directory that contains all the 237 relevant information in the XMLf file and a list of rows each row 238 containing the fiels specified by the other four variables in the r 241 The fields are Servers (s) ports(p) Appnames a.k.a. consumer names(a) 242 and consumer config file. (Note: The consumerName is directly extracted 243 from the config file.) if one field is not desired it should be assigned 244 a value of -1 eg s=-1. other wise their value is mapped from smallest to 245 largest ==> left to right. Note the default values, they will take 246 precedence if not specifyed giving unexpected results 252 sys.stderr.write(
'File doesn\'t exist\n')
255 xmldoc = minidom.parse(XMLf)
257 sys.stderr.write(
'Unable to locate file ' +XMLf +
'\n')
260 sys.stderr.write(
'Parser error\n')
263 configFileNodes=xmldoc.getElementsByTagName(
"configFile")
264 for node
in configFileNodes:
267 order={0:
"s",1:
"p",3:
"a",2:
"c"}
289 if __name__ ==
"__main__":
295 if arg.startswith(
"-"):
296 options+=arg.strip(
"-")
299 if options.count(
"s")+options.count(
"a")+options.count(
"p")+options.count(
"c")!=len(options):
300 sys.stderr.write(
"Sintax Error unrecognised option" )
301 sys.stderr.write( __doc__ )
303 if options.count(
"s")+options.count(
"a")+options.count(
"p")+options.count(
"c")==0:
306 (apptable,appinfo)=
getAppInfo(XMLfile,options.find(
"s"),options.find(
"a"),options.find(
"p"),options.find(
"c"))