| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 2010

# 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.

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

## Variable Documentation

string merge_files::action = "store_true"

Definition at line 106 of file merge_files.py.

string merge_files::default = None,

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.