#!/usr/bin/env python2 ''' Script to copy data quality summary files from the semioffline machines into iRODS Author: Francesca Di Lodovico - Jan 2012 moving to 2012 running (change date) Francesca Di Lodovico - Feb 2011 First version ''' import sys, time, os, commands, shutil, glob def copySummaryFiles(beamYear): '''Function to make a list of the runs in the 2012 subdectories ''' # Create a list with all the _done_ files outFile = '/home/irodsdq/cronjobs/WeeklySummaryFiles_semioff.dat' fo = file(outFile, 'w') filelist = glob.glob( '/t2k/dataquality/summaryFiles/*/' + str(beamYear) + '/*/*' ) for fdone in filelist: prestem = fdone.split(os.path.sep) subDetector = prestem[4] week = prestem[6] name = prestem[7] stringd = '%s %s %s ' %(subDetector, week, name) fo.write(stringd + '\n') fo.close() #print 'Created list of done files' # Now open the list doneRunFile = '/home/irodsdq/cronjobs/WeeklySummaryFiles_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 -lr /KEK-T2K/home/dataquality/data/summaryFiles/ " 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): stemd = aline.split()[-2] stem = aline.split()[-1] stringd = '%s/%s ' %(stemd,stem) copiedFiles.append(stringd ) ''' if (cpts[-1] != ilsfile): ilsfile = cpts[-1] # if ( 'dat' in ilsfile ): #print 'ilsfile ',ilsfile print 'ilsfile ',ilsfile stemd = ilsfile.split()[-2] stem = ilsfile.split()[-1] stringd = '%s/%s ' %(stemd,stem) copiedFiles.append(stringd ) ''' for hline in hlines: ifound = 0 semioff = hline.split() for copiedFile in copiedFiles: semifiles = '%s/%s ' %(semioff[1],semioff[2]) if (copiedFile.strip() in semifiles.strip()): # if (copiedFile.strip() in semioff[2].strip()): ifound = 1 break if ( ifound == 0 ): fname = "/t2k/dataquality/summaryFiles/" + str(semioff[0].strip()) + "/" + str(beamYear) + "/" + str(semioff[1].strip()) + "/" + str(semioff[2].strip()) string0 = "ils /KEK-T2K/home/dataquality/data/summaryFiles/" + \ str(semioff[0].strip()) + "/" + str(beamYear) + "/" + str(semioff[1].strip()) + "/" status0, output0 = commands.getstatusoutput(string0) if(status0 != 0): string1 = "imkdir -p /KEK-T2K/home/dataquality/data/summaryFiles/" + \ str(semioff[0].strip()) + "/" + str(beamYear) + "/" + str(semioff[1].strip()) + "/" status1, output1 = commands.getstatusoutput(string1) if(status1 != 0): print string1,' ',status1,' ',output1 string2 = "iput -fr " + fname + \ " /KEK-T2K/home/dataquality/data/summaryFiles/" + \ str(semioff[0].strip()) + "/" + str(beamYear) + "/" + str(semioff[1].strip()) + "/" status2, output2 = commands.getstatusoutput(string2) if(status2 != 0): print string2,' ',status2,' ',output2 if __name__ == '__main__': # Define by hand the limits for the different neutrino run periods: beamYear = 2012 # 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 copySummaryFiles(beamYear) 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/copySummaryFilesIntoIRODS.log /KEK-T2K/home/dataquality/bookkeeping/copySummaryFilesIntoIRODS.log " status0, output0 = commands.getstatusoutput(string0) if(status0 != 0): print string0,' ',status0,' ',output0