6 from optparse
import OptionParser
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()
13 parser.error(
"wrong number of arguments")
15 project, version, outputfile = args
17 print "Creating %s for %s %s" % (outputfile, project, version)
19 if version.startswith(
'HEAD'):
20 majver, minver, patver = 999, 999, 0
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)
27 outdir = os.path.dirname(outputfile)
28 if not os.path.exists(outdir):
30 print "Creating directory", outdir
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))
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)
44 """ % {
'proj': project.upper(),
'min': minver,
'maj': majver,
'pat': patver }
48 f = open(outputfile,
"r")
55 if outputdata != olddata:
56 open(outputfile,
"w").write(outputdata)
58 if __name__ ==
"__main__":