CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
copyAndRename Namespace Reference

Functions

def main
 

Function Documentation

def copyAndRename.main ( )

Definition at line 5 of file copyAndRename.py.

References beamvalidation.exit(), eostools.ls(), print(), and str.

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