CMS 3D CMS Logo

Functions
copyAndRename Namespace Reference

Functions

def main ()
 

Function Documentation

◆ main()

def copyAndRename.main ( )

Definition at line 5 of file copyAndRename.py.

References beamvalidation.exit(), createfilelist.int, relval_nano.ls, print(), and str.

5 def main():
6  if len(sys.argv) < 3:
7  error = "Usage: copyAndRename fromDir toDir"
8  exit(error)
9  sourceDir = sys.argv[1] + '/'
10  destDir = sys.argv[2] + '/'
11 
12  fileList = ls(sourceDir,".txt")
13  if not os.path.isdir(destDir):
14  error = "WARNING: destination directory doesn't exist! Creating it..."
15  print(error)
16  os.mkdir(destDir)
17  copiedFiles = cp(sourceDir,destDir,fileList)
18 
19  if len(copiedFiles) != len(fileList):
20  error = "ERROR: I couldn't copy all files from castor"
21  exit(error)
22 
23  for fileName in fileList:
24  fullFileName = destDir + fileName
25  runNumber = -1;
26  with open(fullFileName,'r') as file: for line in 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!"
31  exit(error)
32  runNumber = int(line.split(' ')[1])
33  file.close()
34  newFileName = fileName.replace("1_.txt",str(runNumber)+"_1_.txt")
35  if fileName != newFileName:
36  aCmd = "mv " + destDir + fileName + " " + destDir + newFileName
37  print(aCmd)
38  output = subprocess.getstatusoutput(aCmd)
39  if output[0] != 0:
40  print(output[1])
41  else:
42  print("WARNING couldn't find keyword None in file " + fileName)
43 
44 
45 
46 
47 
48 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)
def exit(msg="")