Gaudi Framework, version v23r2p1

Home   Generated: Fri Jun 29 2012
Functions | Variables

merge_files Namespace Reference

Functions

def mergeFiles

Variables

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

Function Documentation

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

Definition at line 12 of file merge_files.py.

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


Variable Documentation

string merge_files::action = "store_true"

Definition at line 106 of file merge_files.py.

Definition at line 86 of file merge_files.py.

string merge_files::dest = "fragFileName"

Definition at line 85 of file merge_files.py.

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

Definition at line 155 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 87 of file merge_files.py.

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

Definition at line 81 of file merge_files.py.

tuple merge_files::sc = 1

Definition at line 136 of file merge_files.py.

tuple merge_files::stamp = open( stampFileName, 'w' )

Definition at line 163 of file merge_files.py.

tuple merge_files::stampFileName = ".stamp"

Definition at line 145 of file merge_files.py.

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

Generated at Fri Jun 29 2012 15:44:15 for Gaudi Framework, version v23r2p1 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004