#!/usr/bin/env python import string, commands, sys, os, getopt, ftplib, time import DFC # the hosts we can get level3 tcl file ftp_list = { 'cdfpcc.fnal.gov' : '/level3tcl/ProductionSplitter', 'cdfkits.fnal.gov' : '/level3tcl/ProductionSplitter', 'cdfcvs.fnal.gov' : '/level3tcl/ProductionSplitter', 'cdfcodebrowser.fnal.gov' : '/level3tcl/ProductionSplitter', } # the file content tclString = "" def getTcl(inStr): global tclString tclString = tclString + inStr def ts(): return time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(time.time())) try: optlist, args = getopt.getopt(sys.argv[1:], '', ['run=', 'output=', ]) except getopt.GetoptError, e: print ts() + ' GetL3TCL: argument error' sys.stdout.flush() sys.exit(1) run = -1 fn = '' for key, val in optlist: if key == '--run': run = string.atoi(val, 10) elif key == '--output': fn = val if run == -1 or fn == '': print ts() + ' GetL3TCL: no run or output assigned.' sys.stdout.flush() sys.exit(1) TagByRun = DFC.getL3TagByRun(run, -1) if not TagByRun.has_key( run ): print ts() + ' GetL3TCL: get level3 tcl tag failed for run number %d.' % run sys.stdout.flush() sys.exit(1) tag = "ProductionSplitter+%d.tcl" % TagByRun[run] tmpStr = "" tmpStr = tmpStr + "export L3LocalLocation=/home/cdfopr/ProductionSplitter/%s\n" % tag done = 1 #for i in ftp_list.keys(): # tcl_path = ftp_list[i] + '/' + tag # # try: # ftp_client = ftplib.FTP( i ) # welcome = ftp_client.login() # except: # print ts() + 'Login to host %s failed' % i # continue # # print ts() + ' \n%s\n' % welcome # # tclString = "" # try: # ftp_client.retrbinary('RETR %s' % tcl_path, getTcl) # except: # print ts() + 'get file %s failed from host %s' % (tcl_path, i) # continue # # ftp_client.close() # # print ts() + 'get file %s successful from host %s' % (tcl_path, i) # done = 0 # # break output = 'source_L3TclLocal.sh' fp2 = open(output, "wt") fp2.write( tmpStr ) fp2.flush() fp2.close() sys.stdout.flush() sys.exit(0) #if done == 0: # fp = open(fn, 'wt') # fp.write( tclString ) # fp.flush() # fp.close() # # sys.stdout.flush() # sys.exit(0) #else: # sys.stdout.flush() # sys.exit(1)