CMS 3D CMS Logo

connectstrParser.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import re
4  def __init__(self,connectstr):
5  self.__connectstr=connectstr
6  self.__pattern=re.compile('(^[\w]+)(://)(.+)(/)(.+)')
7  self.__protocol=''
8  self.__schemaname=''
9  self.__servicename=''
11  def parse(self):
12  result=re.match(self.__pattern,self.__connectstr)
13  if result is not None:
14  protocol=result.group(1)
15  if protocol!='frontier' and protocol!='oracle':
16  raise RuntimeError('unsupported technology '+protocol)
17  self.__protocol=protocol
18  self.__schemaname=result.group(5)
19  self.__servicename=result.group(3)
20  if self.__protocol=='frontier':
21  if self.__servicename.find('(')==-1:
22  if self.__servicename.find('/')==-1:
23  self.__servlettotranslate.append(self.__servicename)
24  elif self.__servicename.find('/') == -1:
25  self.__servlettotranslate.append(self.__servicename.split('(',1)[0])
26  self.__servlettotranslate.append('('+self.__servicename.split('(',1)[1])
27 
28  def protocol(self):
29  return self.__protocol
30  def schemaname(self):
31  return self.__schemaname
32  def service(self):
33  return self.__servicename
34  def needsitelocalinfo(self):
35  if self.__protocol=='frontier':
36  if len(self.__servlettotranslate)==0:
37  return False
38  else :
39  return True
40  else:
41  return False
42  def servlettotranslate(self):
43  """return a list, first is the servlet name, second is whatever additional parameter, if any.
44  """
45  return self.__servlettotranslate
46  def fullfrontierStr(self,schemaname,parameterDict):
47  if len(parameterDict)==0:
48  raise 'empty frontier parameters, cannot construct full connect string'
49  result='frontier://'
50  for k,v in parameterDict.items():
51  ##if attr name=url, concatenate; if attrname=value discard
52  if k=='load' and v[0][0]=='balance':
53  result+='(loadbalance='+v[0][1]+')'
54  continue
55  for (attrname,attrvalue) in v:
56  if attrname=='url':
57  if k=='server':
58  fields=attrvalue.rsplit('/')
59  if len(fields)>3:
60  fields[-1]=self.servlettotranslate()[0]
61  attrvalue='/'.join(fields)
62  result+='('+k+'url='+attrvalue+')'
63  else:
64  result+='('+k+'='+attrvalue+')'
65  if len(self.servlettotranslate())>1:
66  result+=self.servlettotranslate()[1]
67  result+='/'+schemaname
68  return result
69 if __name__ == '__main__':
70  import cacheconfigParser
71  o='oracle://cms_orcoff_prep/CMS_LUMI_DEV_OFFLINE'
72  parser=connectstrParser(o)
73  parser.parse()
74  print(parser.protocol(),parser.service(),parser.schemaname(),parser.needsitelocalinfo())
75  print('case 1')
76  f1='frontier://cmsfrontier.cern.ch:8000/LumiPrep/CMS_LUMI_DEV_OFFLINE'
77  parser=connectstrParser(f1)
78  parser.parse()
79  print(parser.protocol(),parser.service(),parser.schemaname(),parser.needsitelocalinfo())
80  print('case 2')
81  f2='frontier://(serverurl=cmsfrontier.cern.ch:8000/LumiPrep/CMS_LUMI_DEV_OFFLINE)'
82  parser=connectstrParser(f2)
83  parser.parse()
84  print(parser.protocol(),parser.service(),parser.schemaname(),parser.needsitelocalinfo())
85  print('case 3')
86  f3='frontier://(proxyurl=http://cmst0frontier.cern.ch:3128)(proxyurl=http://cmst0frontier.cern.ch:3128)(proxyurl=http://cmst0frontier1.cern.ch:3128)(proxyurl=http://cmst0frontier2.cern.ch:3128)(serverurl=http://cmsfrontier.cern.ch:8000/LumiPrep)(serverurl=http://cmsfrontier.cern.ch:8000)/LumiPrep)(serverurl=http://cmsfrontier1.cern.ch:8000/LumiPrep)(serverurl=http://cmsfrontier2.cern.ch:8000/LumiPrep)(serverurl=http://cmsfrontier3.cern.ch:8000/LumiPrep)(serverurl=http://cmsfrontier4.cern.ch:8000/LumiPrep)/CMS_LUMI_DEV_OFFLINE'
87  parser=connectstrParser(f3)
88  parser.parse()
89  print(parser.protocol(),parser.service(),parser.schemaname(),parser.needsitelocalinfo())
90  print('case 4')
91  f4='frontier://LumiPrep/CMS_LUMI_DEV_OFFLINE'
92  parser=connectstrParser(f4)
93  parser.parse()
94  print(parser.protocol(),parser.service(),parser.schemaname(),parser.needsitelocalinfo(),parser.servlettotranslate())
95  if parser.needsitelocalinfo():
96  sitelocalconfig='/afs/cern.ch/user/x/xiezhen/w1/site-local-config.xml'
98  frontierparser.parse(sitelocalconfig)
99  print('full frontier string')
100  print(parser.fullfrontierStr(parser.schemaname(),frontierparser.parameterdict()))
101  print('case 5')
102  f5='frontier://LumiPrep(otherparameter=value)/CMS_LUMI_DEV_OFFLINE'
103  parser=connectstrParser(f5)
104  parser.parse()
105  print(parser.protocol(),parser.service(),parser.schemaname(),parser.needsitelocalinfo(),parser.servlettotranslate())
106  print(parser.fullfrontierStr(parser.schemaname(),frontierparser.parameterdict()))
107  print('case 6')
108  f6='frontier://LumiCalc/CMS_LUMI_PROD'
109  parser=connectstrParser(f6)
110  parser.parse()
111  print(parser.protocol(),parser.service(),parser.schemaname(),parser.needsitelocalinfo(),parser.servlettotranslate())
112  print(parser.fullfrontierStr(parser.schemaname(),frontierparser.parameterdict()))
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def __init__(self, connectstr)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def fullfrontierStr(self, schemaname, parameterDict)