Gaudi Framework, version v25r2

Home   Generated: Wed Jun 4 2014
 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 
8 lhcb_ver_style = "v(?P<maj_ver>[0-9]+)r(?P<min_ver>[0-9]+)(?:p(?P<pat_ver>[0-9]+))?"
9 atlas_ver_style = "[A-Za-z]+\-(?P<maj_ver>[0-9]+)\-(?P<min_ver>[0-9]+)(?:\-(?P<pat_ver>[0-9]+))?"
10 plain_ver_style = "(?P<maj_ver>[0-9]+)\.(?P<min_ver>[0-9]+)(?:\.(?P<pat_ver>[0-9]+))?"
11 
12 
13 def main():
14  parser = OptionParser(usage="ERROR: Usage %prog <project> <version> <outputfile>")
15  parser.add_option("-q", "--quiet", action="store_true",
16  help="Do not print messages.")
17  opts, args = parser.parse_args()
18  if len(args) != 3:
19  parser.error("wrong number of arguments")
20 
21  project, version, outputfile = args
22  if not opts.quiet:
23  print "Creating %s for %s %s" % (outputfile, project, version)
24 
25  if version.startswith('HEAD'):
26  majver, minver, patver = 999, 999, 0 # special handling
27  else:
28  for style in [lhcb_ver_style, atlas_ver_style, plain_ver_style ] :
29  m = re.match(style, version)
30  if m :
31  break
32  majver = int(m.groupdict()['maj_ver'])
33  minver = int(m.groupdict()['min_ver'])
34  patver = int(m.groupdict()['pat_ver'] or 0)
35 
36  outdir = os.path.dirname(outputfile)
37  if not os.path.exists(outdir):
38  if not opts.quiet:
39  print "Creating directory", outdir
40  os.makedirs(outdir)
41 
42  # Prepare data to be written
43  outputdata = """#ifndef %(proj)s_VERSION
44 /* Automatically generated file: do not modify! */
45 #ifndef CALC_GAUDI_VERSION
46 #define CALC_GAUDI_VERSION(maj,min) (((maj) << 16) + (min))
47 #endif
48 #define %(proj)s_MAJOR_VERSION %(maj)d
49 #define %(proj)s_MINOR_VERSION %(min)d
50 #define %(proj)s_PATCH_VERSION %(pat)d
51 #define %(proj)s_VERSION CALC_GAUDI_VERSION(%(proj)s_MAJOR_VERSION,%(proj)s_MINOR_VERSION)
52 #endif
53 """ % { 'proj': project.upper(), 'min': minver, 'maj': majver, 'pat': patver }
54 
55  # Get the current content of the destination file (if any)
56  try:
57  f = open(outputfile, "r")
58  olddata = f.read()
59  f.close()
60  except IOError:
61  olddata = None
62 
63  # Overwrite the file only if there are changes
64  if outputdata != olddata:
65  open(outputfile, "w").write(outputdata)
66 
67 if __name__ == "__main__":
68  main()

Generated at Wed Jun 4 2014 14:48:58 for Gaudi Framework, version v25r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004