00001
00002 import os,string,sys,commands,time,ConfigParser
00003
00004 MAXRETRIES=10
00005
00006 CONFIGFILE='dbtoconf.cfg'
00007 CONFIG = ConfigParser.ConfigParser()
00008 print 'Reading configuration file from ',CONFIGFILE
00009 CONFIG.read(CONFIGFILE)
00010
00011
00012
00013 print " "
00014 print "dbtoconf.py:"
00015 ACCOUNT=CONFIG.get('Common','Account')
00016 CONNSTRINGGLOBTAG=CONFIG.get('Common','Conn_string_gtag')
00017 GLOBTAG=CONFIG.get('Common','Globtag')
00018 CONFFILE=CONFIG.get('Common','Confoutput')
00019 AUTHPATH=''
00020 try:
00021 AUTHPATH=CONFIG.get('Common','AuthPath')
00022 except:
00023 print "WARNING: No authpath fount in config file"
00024
00025 CONNREP=''
00026 try:
00027 CONNREP=CONFIG.get('Common','Conn_rep')
00028 except:
00029 print "WARNING: No CONN_REP fount in config file"
00030
00031 TAGREP=''
00032 try:
00033 TAGREP=CONFIG.get('Common','Tag_rep')
00034 except:
00035 print "WARNING: No TAG_REP fount in config file"
00036
00037 print
00038 print "Configuration:"
00039 print "================================"
00040 print "Account:",ACCOUNT
00041 print "CONNSTRING:",CONNSTRINGGLOBTAG
00042 print "GLOBALTAG:",GLOBTAG
00043 print "CONF OUTPUT:",CONFFILE
00044 print "Auth. Path:",AUTHPATH
00045 print "Conn. replacement:",CONNREP
00046 print "TAG replacement:",TAGREP
00047 print "================================"
00048
00049
00050 TMPTAG='tmptag.list'
00051
00052
00053 def myparser(input,parstag):
00054 if input.find(parstag)!=-1:
00055 first=input.split(parstag)
00056 second=first[1].split()
00057 out=second[0]
00058 else:
00059 out='-1'
00060 return out
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 root=''
00071 node=''
00072 globparent=''
00073 leafnode=[]
00074 parent=[]
00075 tag=[]
00076 pfn=[]
00077 object=[]
00078 record=[]
00079 connstring=[]
00080 account=[]
00081 label=[]
00082
00083 os.system('rm -f '+TMPTAG)
00084 tagtree_cmd = 'cmscond_tagtree_list -c '+CONNSTRINGGLOBTAG+' -T '+GLOBTAG
00085 if AUTHPATH != '':
00086 tagtree_cmd += ' -P ' + AUTHPATH
00087
00088 os.system(tagtree_cmd +' > '+TMPTAG)
00089
00090 nlines=0
00091 tmp=open(TMPTAG,'r')
00092 while tmp:
00093 line=tmp.readline()
00094 if len(line)==0:
00095 break
00096 nlines=nlines+1
00097 line=string.strip(line)
00098 if line.find('leafnode')==-1:
00099 out=myparser(line,'root:')
00100 if out!='-1':
00101 root=out
00102 out=myparser(line,'node:')
00103 if out!='-1':
00104 node=out
00105 out=myparser(line,'parent:')
00106 if out!='-1':
00107 globparent=out
00108 else:
00109 leafnode.append(myparser(line,'leafnode:'))
00110 parent.append(myparser(line,'parent:'))
00111 tag.append(myparser(line,'tag:'))
00112 pfn.append(myparser(line,'pfn:'))
00113 record.append(myparser(line,'record:'))
00114 label.append(myparser(line,'label:'))
00115 object.append(myparser(line,'object:'))
00116 connstring.append(myparser(line,'pfn:').split('/CMS_COND')[0])
00117 account.append('CMS_COND'+myparser(line,'pfn:').split('/CMS_COND')[1])
00118
00119
00120 tmp.close()
00121 print 'Read '+str(nlines)+' lines...'
00122 print 'Read ',len(leafnode),' leafnodes'
00123 print 'Read ',len(parent),' parent'
00124 print 'Read ',len(tag),' tag'
00125 print 'Read ',len(pfn),' pfn'
00126
00127 if len(leafnode)!=len(parent) or len(leafnode)!=len(tag) or len(leafnode)!=len(pfn):
00128 print "# of leafnodes different from parent/tag/pfn"
00129 sys.exit()
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 conf=open(CONFFILE,'w')
00186 conf.write('[COMMON]\n')
00187 conf.write('connect=sqlite_file:' + GLOBTAG + '.db\n')
00188 conf.write('#connect=oracle://cms_orcoff_int2r/'+ACCOUNT+'\n')
00189 conf.write('#connect=oracle://cms_orcon_prod/'+ACCOUNT+'\n')
00190 conf.write('\n')
00191 conf.write('[TAGINVENTORY]\n')
00192 conf.write('tagdata=\n')
00193 for iline in range(0,len(leafnode)):
00194
00195 if label[iline] == 'None':
00196 outline=' '+tag[iline]+'{pfn='+connstring[iline]+'/'+account[iline]+',objectname='+object[iline]+',recordname='+record[iline]+'}'
00197 else:
00198 outline=' '+tag[iline]+'{pfn='+connstring[iline]+'/'+account[iline]+',objectname='+object[iline]+',recordname='+record[iline]+',labelname='+label[iline]+'}'
00199
00200 if iline != len(leafnode)-1:
00201 outline=outline+';'
00202 outline=outline+'\n'
00203 conf.write(outline)
00204
00205 conf.write("\n")
00206 if TAGREP=='':
00207 conf.write('[TAGTREE '+GLOBTAG+']\n')
00208 else:
00209 conf.write('[TAGTREE '+TAGREP+']\n')
00210
00211 conf.write('root='+root+'\n')
00212 conf.write('nodedata='+node+'{parent='+globparent+'}\n')
00213 conf.write('leafdata=\n')
00214 for ileaf in range(0,len(leafnode)):
00215 outline=' '+leafnode[ileaf]+'{parent='+parent[ileaf]+',tagname='+tag[ileaf]+',pfn='+connstring[ileaf]+'/'+account[ileaf]+'}'
00216 if ileaf!=len(leafnode)-1:
00217 outline=outline+';'
00218 outline=outline+'\n'
00219 conf.write(outline)
00220
00221 conf.close()
00222
00223 print CONFFILE+' ready. Plase have a look'