CMS 3D CMS Logo

cacheconfigParser.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from xml.dom.minidom import parse,parseString,getDOMImplementation,Node
3 
5  def __init__(self):
6  self.__configstr=''
7  self.__configfile=''
8  ###parse result
10  def handleFrontierConnect(self,dom):
11  #print 'handleFrontierConnect'
12  nodelist=dom.getElementsByTagName('frontier-connect')[0].childNodes
13  #print nodelist
14  for node in nodelist:
15  if node.nodeType!=Node.TEXT_NODE and node.nodeType!=Node.COMMENT_NODE:
16  tagname=node.tagName
17  attrs=node.attributes
18  for attrName in attrs.keys():
19  attrNode=attrs.get(attrName)
20  attrValue=attrNode.nodeValue
21  if tagname in self.__parameterDict:
22  self.__parameterDict[tagname].append((attrName,attrValue))
23  else:
24  valuelist=[]
25  valuelist.append((attrName,attrValue))
26  self.__parameterDict[tagname]=valuelist
27  def parse(self,filename):
28  """
29  Parse an XML file by name
30  """
31  dom=parse(filename)
32  self.handleFrontierConnect(dom)
33  dom.unlink()
34  def parseString(self,strbuff):
35  dom=parseString(strbuff)
36  self.handleFrontierConnect(dom)
37  dom.unlink()
38  def proxylist(self):
39  return self.__parameterDict['proxy']
40  def serverlist(self):
41  return self.__parameterDict['server']
42  def parameterdict(self):
43  return self.__parameterDict
44 if __name__ == '__main__':
45  mydocstr="""<frontier-connect><proxy url="http://cmst0frontier.cern.ch:3128"/><proxy url="http://cmst0frontier.cern.ch:3128"/><proxy url="http://cmst0frontier1.cern.ch:3128"/><proxy url="http://cmst0frontier2.cern.ch:3128"/><server url="http://cmsfrontier.cern.ch:8000/FrontierInt"/><server url="http://cmsfrontier.cern.ch:8000/FrontierInt"/><server url="http://cmsfrontier1.cern.ch:8000/FrontierInt"/><server url="http://cmsfrontier2.cern.ch:8000/FrontierInt"/><server url="http://cmsfrontier3.cern.ch:8000/FrontierInt"/><server url="http://cmsfrontier4.cern.ch:8000/FrontierInt"/></frontier-connect>"""
47  p.parseString(mydocstr)
48  print('proxies')
49  print(p.proxylist())
50  print('servers')
51  print(p.serverlist())
52  print('parameterdict')
53  print(p.parameterdict())
54 
55  p.parse('/afs/cern.ch/user/x/xiezhen/w1/site-local-config.xml')
56  print('proxies')
57  print(p.proxylist())
58  print('servers')
59  print(p.serverlist())
60  print('parameterdict')
61  print(p.parameterdict())
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65