#!/usr/bin/env python2 ''' Script to copy data quality summary files from the semioffline machines into iRODS Author: Francesca Di Lodovico - January 2012 Moving to 2012 running Francesca Di Lodovico - March 2011 First version ''' import sys, time, os, commands, shutil, glob def copyDPTFiles(): '''Function to make a list of the runs in the 2011 subdectories ''' # Create a list with all the _done_ files outFile = '/home/irodsdq/cronjobs/DPTFiles_semioff.dat' fo = file(outFile, 'w') filelist = glob.glob( '/home/t2kecal/dev/mhaigh/CalibTFBAuto/tripTDQ/iRODS/*/*.done' ) for fdone in filelist: prestem = fdone.split(os.path.sep) rundir = prestem[8] stringd = '%s ' %(rundir) fo.write(stringd + '\n') fo.close() #print 'Created list of done files' # Now open the list doneRunFile = '/home/irodsdq/cronjobs/DPTFiles_semioff.dat' fh = file(doneRunFile, 'r') hlines = fh.readlines() fh.close() ''' Print the list of files not copied into iRODS yet, as obtained by ils, and then put them into iRODS ''' string22 = "ils -l /KEK-T2K/home/dataquality/data/DPT/ " status22, output22 = commands.getstatusoutput(string22) if ( status22 != 0 ): print 'status22 output22 : ' + str(status22) + ' ' + str(output22) ilsworked = 1 ilsfile = '' copiedFiles = [] for aline in output22.split('\n'): cpts = aline.split("/") if (len(cpts) > 5): if (cpts[-1] != ilsfile): ilsfile = cpts[-1] copiedFiles.append(ilsfile.strip()) for hline in hlines: ifound = 0 for copiedFile in copiedFiles: if (copiedFile in hline.strip()): ifound = 1 break if ( ifound == 0 ): fname = "/home/t2kecal/dev/mhaigh/CalibTFBAuto/tripTDQ/iRODS/" + str(hline.strip()) string1 = "iput -r " + fname + \ " /KEK-T2K/home/dataquality/data/DPT/" status1, output1 = commands.getstatusoutput(string1) if(status1 != 0): print string1,' ',status1,' ',output1 if __name__ == '__main__': # setup the environment variables os.environ["PATH"]="/home/irodsdq/irods/iRODS/clients/icommands/bin:"+os.environ["PATH"] os.environ["irodsEnvFile"]="/home/irodsdq/.irods/.irodsEnv" os.environ["irodsAuthFileName"]="/home/irodsdq/.irods/.irodsA" s0Time = time.time() # current time s1Time = time.localtime(s0Time) # convert current time into a tuple (y,m,d,h,m,s,timezone) s2Time = time.strftime("%Y-%m-%d::%H:%M:%S", s1Time) # converting to human readable file print 'starting cron job: ',s2Time copyDPTFiles() e0Time = time.time() # current time e1Time = time.localtime(e0Time) # convert current time into a tuple (y,m,d,h,m,s,timezone) e2Time = time.strftime("%Y-%m-%d::%H:%M:%S", e1Time) # converting to human readable file print 'ending cron job: ',e2Time string0 = "iput -f /home/irodsdq/cronjobs/copyDPTFilesIntoIRODS.log /KEK-T2K/home/dataquality/bookkeeping/copyDPTFilesIntoIRODS.log " status0, output0 = commands.getstatusoutput(string0) if(status0 != 0): print string0,' ',status0,' ',output0