The Gaudi Framework  v31r0 (aeb156f0)
createProjVersHeader Namespace Reference

Functions

def main ()
 

Variables

string lhcb_ver_style = "v(?P<maj_ver>[0-9]+)r(?P<min_ver>[0-9]+)(?:p(?P<pat_ver>[0-9]+))?"
 
string atlas_ver_style = "[A-Za-z]+\-(?P<maj_ver>[0-9]+)\-(?P<min_ver>[0-9]+)(?:\-(?P<pat_ver>[0-9]+))?"
 
string plain_ver_style = "(?P<maj_ver>[0-9]+)\.(?P<min_ver>[0-9]+)(?:\.(?P<pat_ver>[0-9]+))?"
 

Function Documentation

def createProjVersHeader.main ( )

Definition at line 13 of file createProjVersHeader.py.

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

Variable Documentation

string createProjVersHeader.atlas_ver_style = "[A-Za-z]+\-(?P<maj_ver>[0-9]+)\-(?P<min_ver>[0-9]+)(?:\-(?P<pat_ver>[0-9]+))?"

Definition at line 9 of file createProjVersHeader.py.

string createProjVersHeader.lhcb_ver_style = "v(?P<maj_ver>[0-9]+)r(?P<min_ver>[0-9]+)(?:p(?P<pat_ver>[0-9]+))?"

Definition at line 8 of file createProjVersHeader.py.

string createProjVersHeader.plain_ver_style = "(?P<maj_ver>[0-9]+)\.(?P<min_ver>[0-9]+)(?:\.(?P<pat_ver>[0-9]+))?"

Definition at line 10 of file createProjVersHeader.py.