Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012

createProjVersHeader.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import os
00004 import sys
00005 import re
00006 from optparse import OptionParser
00007 def main():
00008     parser = OptionParser(usage="ERROR: Usage %prog <project> <version> <outputfile>")
00009     parser.add_option("-q", "--quiet", action="store_true",
00010                       help="Do not print messages.")
00011     opts, args = parser.parse_args()
00012     if len(args) != 3:
00013         parser.error("wrong number of arguments")
00014 
00015     project, version, outputfile = args
00016     if not opts.quiet:
00017         print "Creating %s for %s %s" % (outputfile, project, version)
00018 
00019     m = re.match("(v|([A-Za-z]+\-))(?P<maj_ver>[0-9]+)(r|\-)(?P<min_ver>[0-9]+)(?:(p|\-)(?P<pat_ver>[0-9]+))?", version)
00020     majver = int(m.groupdict()['maj_ver'])
00021     minver = int(m.groupdict()['min_ver'])
00022     patver = int(m.groupdict()['pat_ver'] or 0)
00023 
00024     outdir = os.path.dirname(outputfile)
00025     if not os.path.exists(outdir):
00026         if not opts.quiet:
00027             print "Creating directory", outdir
00028         os.makedirs(outdir)
00029 
00030     # Prepare data to be written
00031     outputdata = """#ifndef %(proj)s_VERSION
00032 /* Automatically generated file: do not modify! */
00033 #ifndef CALC_GAUDI_VERSION
00034 #define CALC_GAUDI_VERSION(maj,min) (((maj) << 16) + (min))
00035 #endif
00036 #define %(proj)s_MAJOR_VERSION %(maj)d
00037 #define %(proj)s_MINOR_VERSION %(min)d
00038 #define %(proj)s_PATCH_VERSION %(pat)d
00039 #define %(proj)s_VERSION CALC_GAUDI_VERSION(%(proj)s_MAJOR_VERSION,%(proj)s_MINOR_VERSION)
00040 #endif
00041 """ % { 'proj': project.upper(), 'min': minver, 'maj': majver, 'pat': patver }
00042 
00043     # Get the current content of the destination file (if any)
00044     try:
00045         f = open(outputfile, "r")
00046         olddata = f.read()
00047         f.close()
00048     except IOError:
00049         olddata = None
00050 
00051     # Overwrite the file only if there are changes
00052     if outputdata != olddata:
00053         open(outputfile, "w").write(outputdata)
00054 
00055 if __name__ == "__main__":
00056     main()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:35 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004