summaryrefslogtreecommitdiff
path: root/buildscripts/frob_version.py
blob: 560a8ede646de31fe051788149a84e9dc1272587 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python

from __future__ import with_statement
import tempfile
import sys
import re
import os

def opentemp(basename):
    # The following doesn't work in python before 2.6
#    return tempfile.NamedTemporaryFile('w', -1, ".XXXXXX", basename, '.', False)
    fname = basename +".TMP"
    if os.path.exists(fname):
        raise "not clobbering file %s" % fname
    return open(fname, 'w')

def frob_debian_changelog(version):
    fname = 'debian/changelog'
    with opentemp(fname) as o:
        with open(fname) as i:
            lineno = 0
            for line in i:
                if lineno == 0:
                    newline = re.sub(r'\([^)]*\)', '('+version+')', line)
                    o.write(newline)
                else:
                    o.write(line)
        os.rename(o.name, fname)
        
def frob_rpm_spec(version):
    fname = 'rpm/mongo.spec'
    with opentemp(fname) as o:
        with open(fname) as i:
            frobbed = False
            for line in i:
                if frobbed:
                    o.write(line)
                else:
                    if line.find('Version:') == 0:
                        print >> o, 'Version: ' + version
                        frobbed = True
                    else:
                        o.write(line)
        os.rename(o.name, fname)

def frob_stdafx_cpp(version):
    fname = 'stdafx.cpp'
    with opentemp(fname) as o:
        with open(fname) as i:
            frobbed = False
            for line in i:
                if frobbed:
                    o.write(line)
                else:
                    if re.search(r'const.*char.*versionString\[\].*=', line):
                        o.write('    const char versionString[] = "%s";' % version)
                    else:
                        o.write(line)
        os.rename(o.name, fname)

(progname, version) = sys.argv
if version is None:
    print >> sys.stderr, 'usage: %s VERSION' % progname
    sys.exit(1)
frob_debian_changelog(version)
frob_rpm_spec(version)
## I don't yet know what-all cares about the versionString inside the
## mongo code, so I'm not actually calling this yet.
# frob_stdafx_cpp(version)