createProjVersHeader.py 1.49 KB
Newer Older
1
2
3
4
5
6
#!/usr/bin/env python

import os
import sys
import re
from optparse import OptionParser
marcocle's avatar
marcocle committed
7
def main():
8
9
10
11
12
13
    parser = OptionParser(usage="ERROR: Usage %prog <project> <version> <outputfile>")
    parser.add_option("-q", "--quiet", action="store_true",
                      help="Do not print messages.")
    opts, args = parser.parse_args()
    if len(args) != 3:
        parser.error("wrong number of arguments")
14

15
16
17
    project, version, outputfile = args
    if not opts.quiet:
        print "Creating %s for %s %s" % (outputfile, project, version)
18

19
    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)
20
21
    majver = int(m.groupdict()['maj_ver'])
    minver = int(m.groupdict()['min_ver'])
22
23
    patver = int(m.groupdict()['pat_ver'] or 0)

marcocle's avatar
marcocle committed
24
25
    outdir = os.path.dirname(outputfile)
    if not os.path.exists(outdir):
26
27
        if not opts.quiet:
            print "Creating directory", outdir
marcocle's avatar
marcocle committed
28
        os.makedirs(outdir)
29

30
    open(outputfile, "w").write(
marcocle's avatar
marcocle committed
31
32
33
34
35
36
37
    """#ifndef %(proj)s_VERSION
/* Automatically generated file: do not modify! */
#ifndef CALC_GAUDI_VERSION
#define CALC_GAUDI_VERSION(maj,min) (((maj) << 16) + (min))
#endif
#define %(proj)s_MAJOR_VERSION %(maj)d
#define %(proj)s_MINOR_VERSION %(min)d
38
#define %(proj)s_PATCH_VERSION %(pat)d
marcocle's avatar
marcocle committed
39
40
#define %(proj)s_VERSION CALC_GAUDI_VERSION(%(proj)s_MAJOR_VERSION,%(proj)s_MINOR_VERSION)
#endif
41
"""%{ 'proj': project.upper(), 'min': minver, 'maj': majver, 'pat': patver })
marcocle's avatar
marcocle committed
42
43
44

if __name__ == "__main__":
    main()