release.py 2.29 KB
Newer Older
1 2 3 4 5
#! /usr/bin/env python
"""Update version numbers and release dates for the next release.

usage: release.py version date

6
version should be a string like "3.2.0c1"
7 8 9
date should be a string like "23-Sep-2003"

The following files are updated:
10 11 12 13 14 15
    - setup.py
    - NEWS.txt
    - doc/guide/zodb.tex
    - src/ZEO/__init__.py
    - src/ZEO/version.txt
    - src/ZODB/__init__.py
16 17 18 19 20 21
"""

import fileinput
import os
import re

22 23
# In file filename, replace the first occurrence of regexp pat with
# string repl.
24
def replace(filename, pat, repl):
25
    from sys import stderr as e # fileinput hijacks sys.stdout
26
    foundone = False
27
    for line in fileinput.input([filename], inplace=True, backup="~"):
28 29 30
        if foundone:
            print line,
        else:
31 32
            match = re.search(pat, line)
            if match is not None:
33
                foundone = True
34 35 36 37

                new = re.sub(pat, repl, line)
                print new,

38 39 40
                print >> e, "In %s, replaced:" % filename
                print >> e, "   ", repr(line)
                print >> e, "   ", repr(new)
41 42 43

            else:
                print line,
44 45

    if not foundone:
46 47
        print >> e, "*" * 60, "Oops!"
        print >> e, "    Failed to find %r in %r" % (pat, filename)
48

49 50 51 52
# Nothing in our codebase cares about ZEO/version.txt.  Jeremy said
# someone asked for it so that a shell script could read up the ZEO
# version easily.
# Before ZODB 3.4, the ZEO version was one smaller than the ZODB version;
53 54
# e.g., ZEO 2.2.7 shipped with ZODB 3.2.7.  Now ZEO and ZODB share their
# version number.
55
def write_zeoversion(path, version):
56 57
    with open(path, "w") as f:
        print >> f, version
58 59 60 61

def main(args):
    version, date = args

62
    replace("setup.py",
63 64
            r'^VERSION = "\S+"$',
            'VERSION = "%s"' % version)
65
    replace("src/ZODB/__init__.py",
66
            r'__version__ = "\S+"',
67
            '__version__ = "%s"' % version)
68
    replace("src/ZEO/__init__.py",
69
            r'version = "\S+"',
70 71
            'version = "%s"' % version)
    write_zeoversion("src/ZEO/version.txt", version)
72
    replace("NEWS.txt",
73 74
            r"^Release date: .*",
            "Release date: %s" % date)
75
    replace("doc/guide/zodb.tex",
76 77
            r"release{\S+}",
            "release{%s}" % version)
78 79 80
if __name__ == "__main__":
    import sys
    main(sys.argv[1:])