#!/usr/bin/env python import sys, string, commands, os, glob, getopt try: optlist, args = getopt.getopt(sys.argv[1:], '', ['file=', ]) except getopt.GetoptError, e: print 'SkipReco: argument error' sys.stdout.flush() sys.exit(1) bnTheFile = '' for key, val in optlist: if key == '--file': bnTheFile = val # get the latest ProductionExe.PID files = glob.glob( 'ProductionExe.*' ) if len(files) == 0: print "No file named 'ProductionExe.*' exists, exit..." sys.exit(1) fn = '' last = 0 for i in files: try: stat = os.stat( i ) st_mtime = stat[8] if st_mtime > last: fn = i last = st_mtime except: pass try: line = open( fn ).readline() run, event, record = map(string.strip, string.split(line, ',', 2)) except: print "Read content from %s failed..." % fn sys.exit(1) fn = 'ExcludeEvents.' + bnTheFile try: buf = map(string.strip, open(fn).readlines()) except: buf = [] # add to exclude item = '%s,%s' % (run, event) if not item in buf: buf.append( item ) print "Add run(%s) enevt(%s) to exclude tcl file" % (run, event) buf.sort() # save exclude list fp = open(fn, 'wt') for item in buf: fp.write( item + '\n' ) fp.flush() fp.close() # create exclude tcl file fn = 'tcl_exclude_' + bnTheFile + '.tcl' fp = open(fn, 'wt') fp.write( 'talk DHInput\n' ) for item in buf: run, event = map(string.strip, string.split(item, ',', 1)) fp.write( ' selectEvents exclude run=%s event=%s\n' % (run, event) ) fp.write( 'exit\n' ) fp.flush() fp.close() sys.exit(0)