summaryrefslogtreecommitdiff
path: root/admin/bin/Release.py
blob: 5746212482db583d9308d9aa2d2dd5882912ebb1 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#! /usr/bin/env python

"""Manage releases of Mailman.

Usage: %(program)s [options] tagname

Where `options' are:

    --tag
    -t
        Tag all release files with tagname.

    --TAG
    -T
        Like --tag, but relocates any existing tag.  See `cvs tag -F'.  Only
        one of --tag or --TAG can be given on the command line.

    --package
    -p
        create the distribution package

    --bump
    -b
        Bump the revision number in key files to tagname.  This is done by
        textual substitution.

    --help
    -h
        Print this help message.

    tagname is used in the various commands above.  It should essentially be
    the version number for the release, and is required.

"""

import sys
import os
import string
import re
import time
import tempfile
import getopt

program = sys.argv[0]

def usage(status, msg=''):
    print __doc__ % globals()
    if msg:
        print msg
    sys.exit(status)


_releasedir = None
def releasedir(tagname=None):
    global _releasedir
    if not _releasedir:
        tmpdir = tempfile.gettempdir()
        _releasedir = os.path.join(tmpdir, 'mailman-' + tagname)
    return _releasedir
        


# CVS related commands

def cvsdo(cvscmd):
    os.system('cvs %s' % cvscmd)

def tag_release(tagname, retag):
    # watch out for dots in the name
    table = string.maketrans('.', '_')
    # To be done from writeable repository
    relname = '"Release_' + string.translate(tagname, table) + '"'
    print 'Tagging release with', relname, '...'
    option = ''
    if retag:
	option = '-F'
    cvsdo('tag %s %s' % (option, relname))

def checkout(tagname):
    print 'checking out...',
    # watch out for dots in the name
    table = string.maketrans('.', '_')
    # To be done from writeable repository
    relname = '"Release_' + string.translate(tagname, table) + '"'
    cvsdo('export -k kv -r %s -d %s mailman' % (relname, releasedir()))
    os.rename('%s/doc' % releasedir(), 'mailman-doc')



def make_pkg(tagname):
    print 'Creating release dir', releasedir(tagname), '...'
    # this can't be done from a working directory
    curdir = os.getcwd()
    try:
        os.chdir(tempfile.gettempdir())
        checkout(tagname)
        print 'making tarball...'
        tarball = releasedir() + '.tgz'
        os.system('tar cvf - %s | gzip -c > %s' %
                  ('mailman-' + tagname, tarball))
        os.system('tar cvf - mailman-doc | gzip -c > mailman-doc.gz')
    finally:
        os.chdir(curdir)


def do_bump(newvers):
    print 'doing bump...',
    # hack the index.html file
    print 'index.html...',
    fp = open('admin/www/index.html', 'r+')
    text = fp.read()
    parts = string.split(text, '<!-VERSION--->')
    parts[1] = newvers
    text = string.join(parts, '<!-VERSION--->')
    parts = string.split(text, '<!-DATE--->')
    timestr = time.ctime(time.time())
    parts[1] = timestr[4:11] + timestr[-4:]
    text = string.join(parts, '<!-DATE--->')
    fp.seek(0)
    fp.write(text)
    fp.close()
    # hack the configure.in file
    print 'Version.py...',
    fp_in = open('Mailman/Version.py')
    fp_out = open('Mailman/Version.py.new', 'w')
    matched = 0
    cre = re.compile(r'^VERSION(?P<ws>[ \t]*)=')
    while 1:
        line = fp_in.readline()
        if not line:
            if not matched:
                print 'Error! VERSION line not found'
            break
        mo = cre.search(line)
        if matched or not mo:
            fp_out.write(line)
        else:
            fp_out.write('VERSION%s= "%s"\n' % (mo.group('ws'), newvers))
            matched = 1
    fp_in.close()
    fp_out.close()
    os.rename('Mailman/Version.py.new', 'Mailman/Version.py')
    # update the TODO file
    print 'TODO...'
    os.system('admin/bin/mm2do')


def main():
    try:
	opts, args = getopt.getopt(
	    sys.argv[1:],
	    'btTph',
	    ['bump', 'tag', 'TAG', 'package', 'help'])
    except getopt.error, msg:
	usage(1, msg)

    # required minor rev number
    if len(args) <> 1:
	usage(1, 'tagname argument is required')

    tagname = args[0]

    # default options
    tag = 0
    retag = 0
    package = 0
    bump = 0

    for opt, arg in opts:
	if opt in ('-h', '--help'):
	    usage(0)
	elif opt in ('-t', '--tag'):
	    tag = 1
	elif opt in ('-T', '--TAG'):
	    tag = 1
	    retag = 1
	elif opt in ('-p', '--package'):
	    package = 1
        elif opt in ('-b', '--bump'):
            bump = 1

    # very important!!!
    omask = os.umask(0)
    try:
        if tag:
            tag_release(tagname, retag)

        if package:
            make_pkg(tagname)

        if bump:
            do_bump(tagname)
    finally:
        os.umask(omask)

if __name__ == '__main__':
    main()