CMS 3D CMS Logo

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

Functions

def main
 

Function Documentation

def copyAndRename.main ( )

Definition at line 4 of file copyAndRename.py.

References CommonMethods.cp(), cmsRelvalreport.exit, and eostools.ls().

4 
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:
27  for line in file:
28  if line.find("Runnumber") != -1:
29  tmpRun = int(line.split(' ')[1])
30  if runNumber != -1 and tmpRun != runNumber:
31  error = "This file (" + fileName + ") contains more than 1 run number! I don't know how to deal with it!"
32  exit(error)
33  runNumber = int(line.split(' ')[1])
34  file.close()
35  newFileName = fileName.replace("1_.txt",str(runNumber)+"_1_.txt")
36  if fileName != newFileName:
37  aCmd = "mv " + destDir + fileName + " " + destDir + newFileName
38  print aCmd
39  output = commands.getstatusoutput(aCmd)
40  if output[0] != 0:
41  print output[1]
42  else:
43  print "WARNING couldn't find keyword None in file " + fileName
44 
45 
46 
47 
def ls
Definition: eostools.py:346