Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
createProjVersHeader.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 import sys
5 import re
6 from optparse import OptionParser
7 def main():
8  parser = OptionParser(usage="ERROR: Usage %prog <project> <version> <outputfile>")
9  parser.add_option("-q", "--quiet", action="store_true",
10  help="Do not print messages.")
11  opts, args = parser.parse_args()
12  if len(args) != 3:
13  parser.error("wrong number of arguments")
14 
15  project, version, outputfile = args
16  if not opts.quiet:
17  print "Creating %s for %s %s" % (outputfile, project, version)
18 
19  if version.startswith('HEAD'):
20  majver, minver, patver = 999, 999, 0 # special handling
21  else:
22  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)
23  majver = int(m.groupdict()['maj_ver'])
24  minver = int(m.groupdict()['min_ver'])
25  patver = int(m.groupdict()['pat_ver'] or 0)
26 
27  outdir = os.path.dirname(outputfile)
28  if not os.path.exists(outdir):
29  if not opts.quiet:
30  print "Creating directory", outdir
31  os.makedirs(outdir)
32 
33  # Prepare data to be written
34  outputdata = """#ifndef %(proj)s_VERSION
35 /* Automatically generated file: do not modify! */
36 #ifndef CALC_GAUDI_VERSION
37 #define CALC_GAUDI_VERSION(maj,min) (((maj) << 16) + (min))
38 #endif
39 #define %(proj)s_MAJOR_VERSION %(maj)d
40 #define %(proj)s_MINOR_VERSION %(min)d
41 #define %(proj)s_PATCH_VERSION %(pat)d
42 #define %(proj)s_VERSION CALC_GAUDI_VERSION(%(proj)s_MAJOR_VERSION,%(proj)s_MINOR_VERSION)
43 #endif
44 """ % { 'proj': project.upper(), 'min': minver, 'maj': majver, 'pat': patver }
45 
46  # Get the current content of the destination file (if any)
47  try:
48  f = open(outputfile, "r")
49  olddata = f.read()
50  f.close()
51  except IOError:
52  olddata = None
53 
54  # Overwrite the file only if there are changes
55  if outputdata != olddata:
56  open(outputfile, "w").write(outputdata)
57 
58 if __name__ == "__main__":
59  main()

Generated at Wed Jan 30 2013 17:13:41 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004