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
22 from __future__
import print_function
24 from builtins
import range
26 from xml.dom
import minidom
36 print(
"[%d-%d-%d]"%(l,bn,head.nodeType)+tabs+
"+++++>"+head.tagName)
37 except AttributeError
as e:
38 print(
"[%d-%d-%d]"%(l,bn,head.nodeType)+tabs+
"+++++>"+
str(e))
39 print(
"[%d-%d-%d-v]"%(l,bn,head.nodeType)+tabs+
"."+ (head.nodeValue
or "None"))
41 for katt,vatt
in head.attributes.items():
42 if katt!=
"environmentString":
43 print(tabs+
"%s=%s"%(katt,vatt))
45 print(tabs+
"%s= 'Some Stuff'"%(katt,))
49 for node
in head.childNodes:
55 for item
in head.childNodes:
56 if item.nodeType == 3:
61 for item
in head.childNodes[1:]:
62 if item.nodeType == 3:
63 firstborne.nodeValue+=item.nodeValue
68 """Parses information that's XML format from value to the Docuemnt tree"""
70 if head.firstChild.nodeValue:
71 newNode=minidom.parseString(head.firstChild.nodeValue)
72 for node
in newNode.childNodes:
73 head.appendChild(node.cloneNode(
True))
77 """it searches for the line containing the string consumerName, usually
78 found as a property of the process, and returns the set value found.
81 process.EventStreamHttpReader.consumerName = 'EcalEndcap DQM Consumer'
83 EcalEndcap DQM Consumer
87 consumer = f.readline()
90 consumer=consumer.strip()
91 if "consumerName" in consumer:
92 name=consumer[consumer.index(
"'")+1:consumer.index(
"'",consumer.index(
"'")+1)]
94 consumer = f.readline()
97 sys.stderr.write(
"WARNING: Unable to open file: " + filename +
" from <configFile> section of XML\n")
98 name =
"CONFIG FILE IS M.I.A"
102 """it searches for the line containing the string consumerName, usually
103 found as a property of the process, and returns the set value found.
106 process = cms.Process ("ECALDQM")
113 sys.stderr.write(
"Unable to open file: " + filename +
" from <configFile> section of XML\n")
115 consumer = f.readline()
118 consumer=consumer.strip()
119 if "cms.Process(" in consumer:
120 name=consumer[consumer.index(
"(")+2:consumer.index(
")")-1]
122 consumer = f.readline()
128 branch=branch1[:len(branch1)]
130 for item
in range(len(nodeList)):
131 vals=[v
for (k,v)
in nodeList[idx].attributes.items()]
132 if branch[0]
not in vals:
137 elif len(branch1)==0:
147 key=
min(order.keys())
151 lista=xmldoc.getElementsByTagName(
"XdaqExecutive")
154 table[item.attributes[
"hostname"].value]=
""
155 for item
in table.keys():
156 table[item]=
fillTable(order.copy(),branch + [item])
158 lista=xmldoc.getElementsByTagName(
"XdaqExecutive")
161 pset=item.getElementsByTagName(
"parameterSet")
163 arch=pset[0].firstChild.nodeValue[5:]
167 App=item.getElementsByTagName(
"xc:Application")
168 table[App[0].attributes[
"class"].value]=
""
169 for item
in table.keys():
170 table[item]=
fillTable(order.copy(),branch)
172 lista=xmldoc.getElementsByTagName(
"XdaqExecutive")
175 table[item.attributes[
"port"].value]=
""
176 for item
in table.keys():
177 table[item]=
fillTable(order.copy(),branch + [item])
179 lista=xmldoc.getElementsByTagName(
"XdaqExecutive")
182 pset=item.getElementsByTagName(
"parameterSet")
184 table[
"No additional file"]=
""
186 table[pset[0].firstChild.nodeValue]=
""
187 for item
in table.keys():
188 table[item]=
fillTable(order.copy(),branch)
194 """table => {s:{p:{c:{a:{}}}}}"""
196 for (server,ports)
in table.items():
197 for (port,configfiles)
in ports.items():
198 for (configfile,appnames)
in configfiles.items():
199 for appname
in appnames.keys():
201 for col
in order.values():
207 line.append(configfile)
218 for col
in range(numcols):
221 for col
in range(numcols):
222 if len(line[col])>maxs[col]:
223 maxs[col]=len(line[col])
226 for col
in range(numcols):
227 pline+=line[col].ljust(maxs[col]+2)
234 """ getAppInfo(XMLf,s=0,a=2,p=1,c=3) takes the file name of a valid RCMS
235 configuration and 4 variables that represent which fields are desired
238 It returns a touple containing a directory that contains all the
239 relevant information in the XMLf file and a list of rows each row
240 containing the fiels specified by the other four variables in the r
243 The fields are Servers (s) ports(p) Appnames a.k.a. consumer names(a)
244 and consumer config file. (Note: The consumerName is directly extracted
245 from the config file.) if one field is not desired it should be assigned
246 a value of -1 eg s=-1. other wise their value is mapped from smallest to
247 largest ==> left to right. Note the default values, they will take
248 precedence if not specifyed giving unexpected results
254 sys.stderr.write(
'File doesn\'t exist\n')
257 xmldoc = minidom.parse(XMLf)
259 sys.stderr.write(
'Unable to locate file ' +XMLf +
'\n')
262 sys.stderr.write(
'Parser error\n')
265 configFileNodes=xmldoc.getElementsByTagName(
"configFile")
266 for node
in configFileNodes:
269 order={0:
"s",1:
"p",3:
"a",2:
"c"}
291 if __name__ ==
"__main__":
297 if arg.startswith(
"-"):
298 options+=arg.strip(
"-")
301 if options.count(
"s")+options.count(
"a")+options.count(
"p")+options.count(
"c")!=len(options):
302 sys.stderr.write(
"Sintax Error unrecognised option" )
303 sys.stderr.write( __doc__ )
305 if options.count(
"s")+options.count(
"a")+options.count(
"p")+options.count(
"c")==0:
308 (apptable,appinfo)=
getAppInfo(XMLfile,options.find(
"s"),options.find(
"a"),options.find(
"p"),options.find(
"c"))