Go to the documentation of this file.00001
00002 import sys,os,commands,re
00003 from CommonMethods import *
00004 def main():
00005
00006 sourcePath = "LatestRuns/"
00007
00008 sourceDirList = [sourcePath+"2010A",sourcePath+"2010B",sourcePath+"Commissioning10"]
00009 destDirList = ["2010A","2010B","Commissioning10"]
00010 path = "LatestRuns/"
00011 finalDir = path + "Results/"
00012
00013 if not os.path.isdir(path):
00014 error = "WARNING: path directory doesn't exist! Creating it..."
00015 print error
00016 os.mkdir(path)
00017
00018 if not os.path.isdir(finalDir):
00019 error = "WARNING: final dir directory doesn't exist! Creating it..."
00020 print error
00021 os.mkdir(finalDir)
00022
00023
00024 for n in range(0,len(sourceDirList)):
00025 sourceDir = sourceDirList[n] + '/'
00026 destDir = path + destDirList[n] + '/'
00027 if not dirExists(sourceDir):
00028 print sourceDir + " doesn't exist!"
00029 continue
00030 fileList = ls(sourceDir)
00031 if not os.path.isdir(destDir):
00032 error = "WARNING: destination directory doesn't exist! Creating it..."
00033 print error
00034 os.mkdir(destDir)
00035 copiedFiles = cp(sourceDir,destDir,fileList,False,False)
00036
00037
00038
00039
00040
00041 for fileName in copiedFiles:
00042
00043 regExp = re.search('(\D+)(\d+)_(\d+)_[a-zA-Z0-9]+.txt',fileName)
00044
00045
00046
00047 fullFileName = destDir + fileName
00048 print fullFileName
00049 runNumber = -1
00050 with open(fullFileName,'r') as file:
00051 allTxt = ''
00052 for line in file:
00053 if line.find("Runnumber") != -1:
00054 tmpRun = int(line.split(' ')[1])
00055 if runNumber != -1 and tmpRun != runNumber:
00056 error = "This file (" + fileName + ") contains more than 1 run number!"
00057 if regExp:
00058 newFileName = regExp.group(1) + regExp.group(2) + "_" + str(runNumber) + "_1.txt"
00059 with open(finalDir+newFileName,'w') as outFile:
00060 outFile.writelines(allTxt)
00061 outFile.close()
00062 allTxt = ''
00063
00064
00065
00066
00067
00068 else:
00069 print "WARNING: I can't match the regular espression for file: " + fileName
00070 runNumber = int(line.split(' ')[1])
00071 allTxt += line
00072 file.close()
00073 if regExp:
00074 newFileName = regExp.group(1) + regExp.group(2) + "_" + str(runNumber) + "_" + regExp.group(3) + ".txt"
00075 with open(finalDir+newFileName,'w') as outFile:
00076 outFile.writelines(allTxt)
00077 outFile.close()
00078
00079
00080
00081
00082
00083 if __name__ == "__main__":
00084 main()