2 import sys,os,commands,re
3 from CommonMethods
import *
6 sourcePath =
"LatestRuns/" 8 sourceDirList = [sourcePath+
"2010A",sourcePath+
"2010B",sourcePath+
"Commissioning10"]
9 destDirList = [
"2010A",
"2010B",
"Commissioning10"]
11 finalDir = path +
"Results/" 13 if not os.path.isdir(path):
14 error =
"WARNING: path directory doesn't exist! Creating it..." 18 if not os.path.isdir(finalDir):
19 error =
"WARNING: final dir directory doesn't exist! Creating it..." 24 for n
in range(0,len(sourceDirList)):
25 sourceDir = sourceDirList[n] +
'/' 26 destDir = path + destDirList[n] +
'/' 28 print sourceDir +
" doesn't exist!" 30 fileList =
ls(sourceDir)
31 if not os.path.isdir(destDir):
32 error =
"WARNING: destination directory doesn't exist! Creating it..." 35 copiedFiles =
cp(sourceDir,destDir,fileList,
False,
False)
41 for fileName
in copiedFiles:
43 regExp = re.search(
'(\D+)(\d+)_(\d+)_[a-zA-Z0-9]+.txt',fileName)
47 fullFileName = destDir + fileName
50 with open(fullFileName,
'r') as file: 53 if line.find(
"Runnumber") != -1:
54 tmpRun =
int(line.split(
' ')[1])
55 if runNumber != -1
and tmpRun != runNumber:
56 error =
"This file (" + fileName +
") contains more than 1 run number!" 58 newFileName = regExp.group(1) + regExp.group(2) +
"_" +
str(runNumber) +
"_1.txt" 59 with open(finalDir+newFileName,
'a')
as outFile:
60 outFile.writelines(allTxt)
69 print "WARNING: I can't match the regular espression for file: " + fileName
70 runNumber =
int(line.split(
' ')[1])
74 newFileName = regExp.group(1) + regExp.group(2) +
"_" +
str(runNumber) +
"_" + regExp.group(3) +
".txt" 75 with open(finalDir+newFileName,
'a')
as outFile:
76 outFile.writelines(allTxt)
83 if __name__ ==
"__main__":