CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dbtoconf.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import os,string,sys,commands,time,ConfigParser
3 
4 MAXRETRIES=10 # number of retries before giving up
5 
6 CONFIGFILE='dbtoconf.cfg'
7 CONFIG = ConfigParser.ConfigParser()
8 print 'Reading configuration file from ',CONFIGFILE
9 CONFIG.read(CONFIGFILE)
10 
11 # this is for [COMMON] part of the myconf.conf
12 
13 print " "
14 print "dbtoconf.py:"
15 ACCOUNT=CONFIG.get('Common','Account')
16 CONNSTRINGGLOBTAG=CONFIG.get('Common','Conn_string_gtag')
17 GLOBTAG=CONFIG.get('Common','Globtag')
18 CONFFILE=CONFIG.get('Common','Confoutput')
19 AUTHPATH=''
20 try:
21  AUTHPATH=CONFIG.get('Common','AuthPath')
22 except:
23  print "WARNING: No authpath fount in config file"
24 
25 CONNREP=''
26 try:
27  CONNREP=CONFIG.get('Common','Conn_rep')
28 except:
29  print "WARNING: No CONN_REP fount in config file"
30 
31 TAGREP=''
32 try:
33  TAGREP=CONFIG.get('Common','Tag_rep')
34 except:
35  print "WARNING: No TAG_REP fount in config file"
36 
37 print
38 print "Configuration:"
39 print "================================"
40 print "Account:",ACCOUNT
41 print "CONNSTRING:",CONNSTRINGGLOBTAG
42 print "GLOBALTAG:",GLOBTAG
43 print "CONF OUTPUT:",CONFFILE
44 print "Auth. Path:",AUTHPATH
45 print "Conn. replacement:",CONNREP
46 print "TAG replacement:",TAGREP
47 print "================================"
48 
49 # this is for tags
50 TMPTAG='tmptag.list'
51 
52 
53 def myparser(input,parstag):
54  if input.find(parstag)!=-1:
55  first=input.split(parstag)
56  second=first[1].split()
57  out=second[0]
58  else:
59  out='-1'
60  return out
61 
62 # main start here
63 ######################################
64 # initialization
65 
66 
67 
68 
69 
70 root=''
71 node=''
72 globparent=''
73 leafnode=[]
74 parent=[]
75 tag=[]
76 pfn=[]
77 object=[]
78 record=[]
79 connstring=[]
80 account=[]
81 label=[]
82 
83 os.system('rm -f '+TMPTAG)
84 tagtree_cmd = 'cmscond_tagtree_list -c '+CONNSTRINGGLOBTAG+' -T '+GLOBTAG
85 if AUTHPATH != '':
86  tagtree_cmd += ' -P ' + AUTHPATH
87 
88 os.system(tagtree_cmd +' > '+TMPTAG)
89 
90 nlines=0
91 tmp=open(TMPTAG,'r')
92 while tmp:
93  line=tmp.readline()
94  if len(line)==0:
95  break
96  nlines=nlines+1
97  line=string.strip(line)
98  if line.find('leafnode')==-1:
99  out=myparser(line,'root:')
100  if out!='-1':
101  root=out
102  out=myparser(line,'node:')
103  if out!='-1':
104  node=out
105  out=myparser(line,'parent:')
106  if out!='-1':
107  globparent=out
108  else:
109  leafnode.append(myparser(line,'leafnode:'))
110  parent.append(myparser(line,'parent:'))
111  tag.append(myparser(line,'tag:'))
112  pfn.append(myparser(line,'pfn:'))
113  record.append(myparser(line,'record:'))
114  label.append(myparser(line,'label:'))
115  object.append(myparser(line,'object:'))
116  connstring.append(myparser(line,'pfn:').split('/CMS_COND')[0])
117  account.append('CMS_COND'+myparser(line,'pfn:').split('/CMS_COND')[1])
118 # print nlines,line
119 
120 tmp.close()
121 print 'Read '+str(nlines)+' lines...'
122 print 'Read ',len(leafnode),' leafnodes'
123 print 'Read ',len(parent),' parent'
124 print 'Read ',len(tag),' tag'
125 print 'Read ',len(pfn),' pfn'
126 
127 if len(leafnode)!=len(parent) or len(leafnode)!=len(tag) or len(leafnode)!=len(pfn):
128  print "# of leafnodes different from parent/tag/pfn"
129  sys.exit()
130 
131 #output
132 #print root,node,globparent
133 
134 
135 # for i in range(0,len(leafnode)):
136 # command='cmscond_taginventory_list -c '+CONNSTRINGGLOBTAG+' -t '+tag[i]
137 # if AUTHPATH != '':
138 # command += ' -P ' + AUTHPATH
139 
140 # # print "COMMAND=",command
141 # # put in a loop until it succeed
142 # for ntime in range(0,MAXRETRIES):
143 # fullout=commands.getoutput(command)
144 # # 'cmscond_taginventory_list -c'+CONNSTRINGGLOBTAG+' -t '+tag[i])
145 # linesout=fullout.split('\n')
146 # # print fullout
147 # # print len(linesout)
148 # if(len(linesout)>1):
149 # # success
150 # break
151 # print "Try: ",ntime, ".....",tag[i]
152 # time.sleep(0.5)
153 # if(len(linesout)<=1):
154 # print "Unable to get information on tag:",tag[i]," after ", MAXRETRIES, "retries"
155 # print "Giving up here..."
156 # sys.exit(1)
157 
158 # # print tag[i]
159 # for i2 in range(0,len(linesout)):
160 # # print linesout[i2]
161 # if linesout[i2].split()[2]==pfn[i]:
162 # #same pfn and tag
163 # object.append(linesout[i2].split()[3])
164 # record.append(linesout[i2].split()[4])
165 # if CONNREP!='':
166 # connstring.append(CONNREP)
167 # else:
168 # connstring.append(pfn[i].split('/CMS_COND')[0])
169 # account.append('CMS_COND'+pfn[i].split('/CMS_COND')[1])
170 # #print "TAG: " + tag[i] + " LABEL: " + linesout[i2].split()[5]
171 # label.append(linesout[i2].split()[5])
172 
173 # print "Leafnode:",i,leafnode[i]
174 # print "Parent=",parent[i]
175 # print "Tag=",tag[i]
176 # print "Pfn=",pfn[i]
177 # print "Object=",object[i]
178 # print "Record=",record[i]
179 # print "Connstring=",connstring[i]
180 # print "Account=",account[i]
181 # print "=================================="
182 
183 
184 # open output conf file
185 conf=open(CONFFILE,'w')
186 conf.write('[COMMON]\n')
187 conf.write('connect=sqlite_file:' + GLOBTAG + '.db\n')
188 conf.write('#connect=oracle://cms_orcoff_int2r/'+ACCOUNT+'\n')
189 conf.write('#connect=oracle://cms_orcon_prod/'+ACCOUNT+'\n')
190 conf.write('\n')
191 conf.write('[TAGINVENTORY]\n')
192 conf.write('tagdata=\n')
193 for iline in range(0,len(leafnode)):
194  # print iline
195  if label[iline] == 'None':
196  outline=' '+tag[iline]+'{pfn='+connstring[iline]+'/'+account[iline]+',objectname='+object[iline]+',recordname='+record[iline]+'}'
197  else:
198  outline=' '+tag[iline]+'{pfn='+connstring[iline]+'/'+account[iline]+',objectname='+object[iline]+',recordname='+record[iline]+',labelname='+label[iline]+'}'
199 
200  if iline != len(leafnode)-1:
201  outline=outline+';'
202  outline=outline+'\n'
203  conf.write(outline)
204 
205 conf.write("\n")
206 if TAGREP=='':
207  conf.write('[TAGTREE '+GLOBTAG+']\n')
208 else:
209  conf.write('[TAGTREE '+TAGREP+']\n')
210 
211 conf.write('root='+root+'\n')
212 conf.write('nodedata='+node+'{parent='+globparent+'}\n')
213 conf.write('leafdata=\n')
214 for ileaf in range(0,len(leafnode)):
215  outline=' '+leafnode[ileaf]+'{parent='+parent[ileaf]+',tagname='+tag[ileaf]+',pfn='+connstring[ileaf]+'/'+account[ileaf]+'}'
216  if ileaf!=len(leafnode)-1:
217  outline=outline+';'
218  outline=outline+'\n'
219  conf.write(outline)
220 
221 conf.close()
222 
223 print CONFFILE+' ready. Plase have a look'
def myparser
Definition: dbtoconf.py:53
double split
Definition: MVATrainer.cc:139