CMS 3D CMS Logo

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