CMS 3D CMS Logo

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

Functions

def main
 

Function Documentation

def rename.main ( )

Definition at line 6 of file rename.py.

References trklet.dirExists(), eostools.ls(), print(), sistrip::SpyUtilities.range(), and str.

6 
7 def main():
8 # sourcePath = "/castor/cern.ch/cms/store/caf/user/uplegger/Workflows/Repro_2011Feb24/"
9  sourcePath = "LatestRuns/"
10 # sourcePath = "Files/"
11  sourceDirList = [sourcePath+"2010A",sourcePath+"2010B",sourcePath+"Commissioning10"]
12  destDirList = ["2010A","2010B","Commissioning10"]
13  path = "LatestRuns/"
14  finalDir = path + "Results/"
15 
16  if not os.path.isdir(path):
17  error = "WARNING: path directory doesn't exist! Creating it..."
18  print(error)
19  os.mkdir(path)
20 
21  if not os.path.isdir(finalDir):
22  error = "WARNING: final dir directory doesn't exist! Creating it..."
23  print(error)
24  os.mkdir(finalDir)
25 
26  #for n in range(0,3):
27  for n in range(0,len(sourceDirList)):
28  sourceDir = sourceDirList[n] + '/'
29  destDir = path + destDirList[n] + '/'
30  if not dirExists(sourceDir):
31  print(sourceDir + " doesn't exist!")
32  continue
33  fileList = ls(sourceDir)
34  if not os.path.isdir(destDir):
35  error = "WARNING: destination directory doesn't exist! Creating it..."
36  print(error)
37  os.mkdir(destDir)
38  copiedFiles = cp(sourceDir,destDir,fileList,False,False)
39 
40  #if len(copiedFiles) != len(fileList):
41  # error = "ERROR: I couldn't copy all files"
42  # exit(error)
43 # exit("ok")
44  for fileName in copiedFiles:
45  #regExp = re.search('(\D+)(\d+)_(\d+)_.txt',fileName)
46  regExp = re.search('(\D+)(\d+)_(\d+)_[a-zA-Z0-9]+.txt',fileName)
47  #if regExp:
48  #print regExp.group(1) + regExp.group(2) + "_" + str(1) + "_" + regExp.group(3) + ".txt"
49 
50  fullFileName = destDir + fileName
51  print(fullFileName)
52  runNumber = -1
53  with open(fullFileName,'r') as file:
54  allTxt = ''
55  for line in file:
56  if line.find("Runnumber") != -1:
57  tmpRun = int(line.split(' ')[1])
58  if runNumber != -1 and tmpRun != runNumber:
59  error = "This file (" + fileName + ") contains more than 1 run number!"
60  if regExp:
61  newFileName = regExp.group(1) + regExp.group(2) + "_" + str(runNumber) + "_1.txt"
62  with open(finalDir+newFileName,'a') as outFile:
63  outFile.writelines(allTxt)
64  outFile.close()
65  allTxt = ''
66  #aCmd = "cp " + destDir + fileName + " " + finalDir + newFileName
67  #print aCmd
68  #output = subprocess.getstatusoutput(aCmd)
69  #if output[0] != 0:
70  #print output[1]
71  else:
72  print("WARNING: I can't match the regular espression for file: " + fileName)
73  runNumber = int(line.split(' ')[1])
74  allTxt += line
75  file.close()
76  if regExp:
77  newFileName = regExp.group(1) + regExp.group(2) + "_" + str(runNumber) + "_" + regExp.group(3) + ".txt"
78  with open(finalDir+newFileName,'a') as outFile:
79  outFile.writelines(allTxt)
80  outFile.close()
81 
82 
83 
84 
def ls
Definition: eostools.py:349
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
int dirExists(const std::string &path)
Definition: Util.h:121
def main
Definition: rename.py:6
#define str(s)