126 allowedActions = [
'batchupdate',
'update',
'dump']
127 allowedFlags = [
'UNKNOWN',
'GOOD',
'BAD',
'SUSPECT']
129 parser.add_argument(
'action',choices=allowedActions,help=
'command actions')
130 parser.add_argument(
'-c',dest=
'connect',action=
'store',required=
True,help=
'connect string to lumiDB')
131 parser.add_argument(
'-P',dest=
'authpath',action=
'store',required=
True,help=
'path to authentication file')
132 parser.add_argument(
'-i',dest=
'inputfile',action=
'store',help=
'lumi range selection file,required for batchupdate action')
133 parser.add_argument(
'-o',dest=
'outputfile',action=
'store',help=
'output to csv file')
134 parser.add_argument(
'-r',dest=
'runnumber',action=
'store',type=int,help=
'run number,optional')
135 parser.add_argument(
'-runls',dest=
'runls',action=
'store',help=
'selection string,optional. Example [1234:[],4569:[1,1],[2,100]]')
136 parser.add_argument(
'-flag',dest=
'flag',action=
'store',default=
'UNKNOWN',help=
'flag string,optional')
137 parser.add_argument(
'--verbose',dest=
'verbose',action=
'store_true',help=
'verbose mode for printing' )
138 parser.add_argument(
'--debug',dest=
'debug',action=
'store_true',help=
'debug')
139 options=parser.parse_args()
140 if options.flag.upper()
not in allowedFlags:
141 print 'unrecognised flag ',options.flag.upper()
143 os.environ[
'CORAL_AUTH_PATH'] = options.authpath
144 connectstring=options.connect
145 svc = coral.ConnectionService()
146 msg=coral.MessageStream(
'')
148 msg.setMsgVerbosity(coral.message_Level_Debug)
150 msg.setMsgVerbosity(coral.message_Level_Error)
151 session=svc.connect(connectstring,accessMode=coral.access_Update)
152 session.typeConverter().setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)")
153 session.typeConverter().setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)")
157 msg=coral.MessageStream(
'')
158 msg.setMsgVerbosity(coral.message_Level_Debug)
160 if options.action==
'batchupdate':
162 if not options.inputfile:
163 print 'inputfile -i option is required for batchupdate'
165 csvReader=csv.reader(open(options.inputfile),delimiter=
',')
166 for row
in csvReader:
169 fieldrun=str(row[0]).
strip()
170 fieldls=str(row[1]).
strip()
173 if not result.has_key(int(fieldrun)):
174 result[int(fieldrun)]=[]
175 result[int(fieldrun)].
append([int(fieldls),fieldstatus,fieldcomment])
177 if options.action==
'update':
182 if not options.runls
and not options.runnumber:
183 print 'option -runls or -r is required for update'
186 print 'option -flag is required for update'
188 if options.flag.upper()
not in allowedFlags:
189 print 'unrecognised flag ',options.flag
191 if options.runnumber:
192 runlsjson=
'{"'+str(options.runnumber)+
'":[]}'
196 runsandls=sparser.runsandls()
198 statusStr=options.flag
199 for run,lslist
in runsandls.items():
200 if not result.has_key(run):
203 result[run].
append([ls,statusStr,commentStr])
205 if options.action==
'dump':
206 if options.runls
or options.inputfile:
210 runsandls=sparser.runsandls()
211 if options.inputfile:
213 runsandls=p.runsandls()
214 for runnum,lslist
in runsandls.items():
216 if dataperrun.has_key(runnum):
217 result[runnum]=dataperrun[runnum]
224 if options.outputfile:
227 for perrundata
in result[run]:
228 r.writeRow([str(run),str(perrundata[0]),perrundata[1],perrundata[2]])
232 if len(result[run])==0:
233 print str(run),
'no validation data'
235 for lsdata
in result[run]:
236 print str(run)+
','+str(lsdata[0])+
','+lsdata[1]+
','+lsdata[2]
del svc