| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# merge_genconfDb.py

Go to the documentation of this file.

    00001 #!/usr/bin/env python
    00002
    00003 # @file: GaudiPolicy/cmt/fragments/merge_genconfDb.py
    00004 # @purpose: merge <library>_confDb.py files into a 'per-project' confDb.py file
    00005 # @author: Sebastien Binet <binet@cern.ch>
    00006
    00007 import os
    00008 import sys
    00009 from datetime import datetime
    00010
    00011 def usage(sc = 1) :
    00012     print 'Usage:'
    00013     print '  merge_genconfDb <confDbFileName> <project_merged_confDbFileName>'
    00014     print '  return status',sc
    00015     sys.exit(sc)
    00016
    00017 import mmap
    00018 def mergeConfDbFiles( libConfDbFileName, projConfDbFileName ):
    00019     confDb = os.path.basename( libConfDbFileName ).replace( ".py", "" )
    00020     startMark = "#--Begin %s" % ( confDb + os.linesep )
    00021     timeMark  = "#--Date inserted: %s" % ( str(datetime.now()) + os.linesep )
    00022     endMark   = "#--End %s" % ( confDb + os.linesep )
    00023
    00024     try:
    00025         newLines = []
    00026         projConfDb   = open( projConfDbFileName, 'r+' )
    00027         projFileSize = os.path.getsize( projConfDb.name )
    00028
    00029         if projFileSize > 0:
    00030             memProjConfDb = mmap.mmap( projConfDb.fileno(),
    00031                                        projFileSize,
    00032                                        access = mmap.ACCESS_WRITE )
    00033             startMarkIdx = memProjConfDb.find(startMark)
    00034             endMarkIdx   = memProjConfDb.find(endMark)
    00035             if startMarkIdx != -1 and endMarkIdx != -1:
    00036                 newLines = memProjConfDb[:startMarkIdx].strip() + \
    00037                            memProjConfDb[endMarkIdx+
    00038                                          len(endMark):].strip()
    00039             else:
    00040                 newLines = memProjConfDb[:].strip()
    00041             newLines = newLines.split(os.linesep)
    00042             memProjConfDb.close()
    00043             pass
    00044
    00045         projConfDb.seek(0)
    00046         projConfDb.truncate(0)
    00047         if len(newLines) > 0:
    00048             projConfDb.writelines( os.linesep.join(newLines) )
    00049             pass
    00050         projConfDb.writelines(
    00051             os.linesep +
    00052             startMark  +
    00053             timeMark   +
    00054             "".join( [l for l in open( libConfDbFileName, 'r' ) ] ) +
    00055             endMark
    00056             )
    00057     except IOError, err:
    00058         print "ERROR:",err
    00059         usage(2)
    00060     return
    00061
    00062 if __name__ == "__main__":
    00063     mergeConfDbFiles( libConfDbFileName  = sys.argv[1],
    00064                       projConfDbFileName = sys.argv[2] )
    00065
    00066     sys.exit(0)