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