12 from __future__
import print_function
16 from optparse
import OptionParser
18 lhcb_ver_style =
"v(?P<maj_ver>[0-9]+)r(?P<min_ver>[0-9]+)(?:p(?P<pat_ver>[0-9]+))?" 19 atlas_ver_style =
"[A-Za-z]+\-(?P<maj_ver>[0-9]+)\-(?P<min_ver>[0-9]+)(?:\-(?P<pat_ver>[0-9]+))?" 20 plain_ver_style =
"(?P<maj_ver>[0-9]+)\.(?P<min_ver>[0-9]+)(?:\.(?P<pat_ver>[0-9]+))?" 24 parser = OptionParser(
25 usage=
"ERROR: Usage %prog <project> <version> <outputfile>")
27 "-q",
"--quiet", action=
"store_true", help=
"Do not print messages.")
28 opts, args = parser.parse_args()
30 parser.error(
"wrong number of arguments")
32 project, version, outputfile = args
34 print(
"Creating %s for %s %s" % (outputfile, project, version))
36 for style
in [lhcb_ver_style, atlas_ver_style, plain_ver_style]:
37 m = re.match(style, version)
39 majver = int(m.groupdict()[
'maj_ver'])
40 minver = int(m.groupdict()[
'min_ver'])
41 patver = int(m.groupdict()[
'pat_ver']
or 0)
46 majver, minver, patver = 999, 999, 0
48 outdir = os.path.dirname(outputfile)
49 if not os.path.exists(outdir):
51 print(
"Creating directory", outdir)
55 outputdata =
"""#ifndef %(proj)s_VERSION 56 /* Automatically generated file: do not modify! */ 57 #ifndef CALC_GAUDI_VERSION 58 #define CALC_GAUDI_VERSION(maj,min) (((maj) << 16) + (min)) 60 #define %(proj)s_MAJOR_VERSION %(maj)d 61 #define %(proj)s_MINOR_VERSION %(min)d 62 #define %(proj)s_PATCH_VERSION %(pat)d 63 #define %(proj)s_VERSION CALC_GAUDI_VERSION(%(proj)s_MAJOR_VERSION,%(proj)s_MINOR_VERSION) 66 'proj': project.upper(),
74 f = open(outputfile,
"r")
81 if outputdata != olddata:
82 open(outputfile,
"w").write(outputdata)
85 if __name__ ==
"__main__":