3 from CommonMethods
import *
6 error =
"Usage: copyAndRename fromDir toDir" 8 sourceDir = sys.argv[1] +
'/' 9 destDir = sys.argv[2] +
'/' 11 fileList =
ls(sourceDir,
".txt")
12 if not os.path.isdir(destDir):
13 error =
"WARNING: destination directory doesn't exist! Creating it..." 16 copiedFiles =
cp(sourceDir,destDir,fileList)
18 if len(copiedFiles) != len(fileList):
19 error =
"ERROR: I couldn't copy all files from castor" 22 for fileName
in fileList:
23 fullFileName = destDir + fileName
25 with open(fullFileName,
'r') as file: 27 if line.find(
"Runnumber") != -1:
28 tmpRun =
int(line.split(
' ')[1])
29 if runNumber != -1
and tmpRun != runNumber:
30 error =
"This file (" + fileName +
") contains more than 1 run number! I don't know how to deal with it!" 32 runNumber =
int(line.split(
' ')[1])
34 newFileName = fileName.replace(
"1_.txt",
str(runNumber)+
"_1_.txt")
35 if fileName != newFileName:
36 aCmd =
"mv " + destDir + fileName +
" " + destDir + newFileName
38 output = commands.getstatusoutput(aCmd)
42 print "WARNING couldn't find keyword None in file " + fileName
48 if __name__ ==
"__main__":