Gaudi Framework, version v23r3

Home   Generated: Thu Jun 28 2012
Functions | Variables

merge_files Namespace Reference

Functions

def mergeFiles

Variables

tuple parser = OptionParser(usage="usage: %prog [options]")
string action = "append"
string dest = "fragFileNames"
list default = []
string help = "The path and name of the file one wants to merge into the 'master' one"
int sc = 1
string stampFileName = ".stamp"
tuple globalLock = locker.LockFile(os.environ["GAUDI_BUILD_LOCK"], temporary = True)

Function Documentation

def merge_files::mergeFiles (   fragFileNames,
  mergedFileName,
  commentChar,
  doMerge 
)

Definition at line 12 of file merge_files.py.

00013                                                                      :
00014 
00015     startMark = "%s --Beg " % commentChar
00016     timeMark  = "%s --Date inserted: %s" % (commentChar, datetime.now())
00017     endMark   = "%s --End " % commentChar
00018     nameOffset = len(startMark)
00019 
00020     basenames = map(os.path.basename, fragFileNames)
00021 
00022     isNewFile = not os.path.exists(mergedFileName)
00023 
00024     # create an empty file if it does not exist
00025     # "append mode" ensures that, in case of two processes trying to
00026     # create the file, they do not truncate each other file
00027     if isNewFile:
00028         # check if the destination directory exists
00029         path_to_file = os.path.split(mergedFileName)[0]
00030         if not os.path.isdir(path_to_file):
00031             # if doesn't exist, create it
00032             os.makedirs(path_to_file)
00033         open(mergedFileName,'a')
00034 
00035     mergedFile = open( mergedFileName, 'r+' )
00036 
00037     # locking file, gaining exclusive access to it
00038     lock = locker.lock( mergedFile )
00039     try:
00040 
00041         newLines = [ ]
00042         skipBlock = ""
00043         for line in mergedFile.readlines():
00044             if line.startswith(startMark) and line[nameOffset:].strip() in basenames:
00045                 skipBlock = endMark + line[nameOffset:].strip()
00046                 # remove all the empty lines occurring before the start mark
00047                 while (len(newLines) > 0) and (newLines[-1].strip() == ''):
00048                     newLines.pop()
00049             if not skipBlock:
00050                 newLines.append(line)
00051             if line.startswith(skipBlock):
00052                 skipBlock = ""
00053         if skipBlock:
00054             print "WARNING: missing end mark ('%s')" % skipBlock
00055 
00056         if doMerge:
00057             for f in fragFileNames:
00058                 # I do not want to add 2 empty lines at the beginning of a file
00059                 if newLines:
00060                     newLines.append('\n\n')
00061                 bf = os.path.basename(f)
00062                 newLines.append(startMark + bf + '\n')
00063                 newLines.append(timeMark + '\n')
00064                 fileData = open(f, 'r').read()
00065                 newLines.append(fileData)
00066                 if fileData and fileData[-1] != '\n':
00067                     newLines.append('\n')
00068                 newLines.append(endMark + bf + '\n')
00069 
00070         mergedFile.seek(0)
00071         mergedFile.truncate(0)
00072         mergedFile.writelines(newLines)
00073 
00074     finally:
00075         # unlock file
00076         locker.unlock( mergedFile )
00077 
00078     return 0


Variable Documentation

Definition at line 86 of file merge_files.py.

Definition at line 88 of file merge_files.py.

string merge_files::dest = "fragFileNames"

Definition at line 87 of file merge_files.py.

merge_files::globalLock = locker.LockFile(os.environ["GAUDI_BUILD_LOCK"], temporary = True)

Definition at line 163 of file merge_files.py.

string merge_files::help = "The path and name of the file one wants to merge into the 'master' one"

Definition at line 89 of file merge_files.py.

tuple merge_files::parser = OptionParser(usage="usage: %prog [options]")

Definition at line 82 of file merge_files.py.

tuple merge_files::sc = 1

Definition at line 144 of file merge_files.py.

tuple merge_files::stampFileName = ".stamp"

Definition at line 153 of file merge_files.py.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 12:30:25 for Gaudi Framework, version v23r3 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004