8 error =
"Usage: copyAndRename fromDir toDir"
10 sourceDir = sys.argv[1] +
'/'
11 destDir = sys.argv[2] +
'/'
13 fileList =
ls(sourceDir,
".txt")
14 if not os.path.isdir(destDir):
15 error =
"WARNING: destination directory doesn't exist! Creating it..."
18 copiedFiles =
cp(sourceDir,destDir,fileList)
20 if len(copiedFiles) != len(fileList):
21 error =
"ERROR: I couldn't copy all files from castor"
24 for fileName
in fileList:
25 fullFileName = destDir + fileName
27 with open(fullFileName,
'r') as file:
29 if line.find(
"Runnumber") != -1:
30 tmpRun = int(line.split(
' ')[1])
31 if runNumber != -1
and tmpRun != runNumber:
32 error =
"This file (" + fileName +
") contains more than 1 run number! I don't know how to deal with it!"
34 runNumber = int(line.split(
' ')[1])
36 newFileName = fileName.replace(
"1_.txt",
str(runNumber)+
"_1_.txt")
37 if fileName != newFileName:
38 aCmd =
"mv " + destDir + fileName +
" " + destDir + newFileName
40 output = subprocess.getstatusoutput(aCmd)
44 print(
"WARNING couldn't find keyword None in file " + fileName)