~xav0989/ubuntu/vivid/mailman/ubuntu-logo

« back to all changes in this revision

Viewing changes to admin/bin/release

  • Committer: Bazaar Package Importer
  • Author(s): Thijs Kinkhorst
  • Date: 2008-04-24 19:30:49 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080424193049-jy5fa9tus40tjbmn
Tags: 1:2.1.10-2
Apply upstream patch to fix regression in cmd_subscribe
so that email subscribe to the -subscribe or -join address or the
-request address with a bare 'subscribe' command results in the message
being shunted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
#
3
 
# Copyright (C) 1998-2006 by the Free Software Foundation, Inc.
4
 
#
5
 
# This program is free software; you can redistribute it and/or
6
 
# modify it under the terms of the GNU General Public License
7
 
# as published by the Free Software Foundation; either version 2
8
 
# of the License, or (at your option) any later version.
9
 
#
10
 
# This program is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
# GNU General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License
16
 
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18
 
# USA.
19
 
 
20
 
# XXX This file does not need to be compatible with Python 2.1.  It is only
21
 
# used by the release manager.
22
 
 
23
 
import os
24
 
import re
25
 
import sys
26
 
import time
27
 
import errno
28
 
import optparse
29
 
import tempfile
30
 
 
31
 
from subprocess import Popen, PIPE
32
 
from urlparse import urlparse
33
 
 
34
 
 
35
 
__revision__ = '$Revision: 8022 $'
36
 
 
37
 
parts = __revision__.split()
38
 
if len(parts) == 3:
39
 
    __version__ = parts[1]
40
 
else:
41
 
    __version__ = parts[0]
42
 
 
43
 
 
44
 
SLASH   = '/'
45
 
SPACE   = ' '
46
 
 
47
 
 
48
 
 
49
 
def calculate_urls(relname):
50
 
    srcurl = None
51
 
    stdout, stderr = do('svn info')
52
 
    for line in stdout.splitlines():
53
 
        key, val = line.split(':', 1)
54
 
        if key.lower() == 'url':
55
 
            srcurl = val
56
 
            break
57
 
    else:
58
 
        print >> sys.stderr, 'No source url found'
59
 
        sys.exit(1)
60
 
    scheme, netloc, path, params, query, frag = urlparse(srcurl)
61
 
    if params or query or frag:
62
 
        print >> sys.stderr, 'src url has params, query and/or frag'
63
 
        sys.exit(1)
64
 
    parts = path.split(SLASH)
65
 
    # XXX Fix this to work on the trunk too
66
 
    for i, part in enumerate(parts):
67
 
        if part == 'branches':
68
 
            break
69
 
    else:
70
 
        print >> sys.stderr, 'No branches directory found in src url'
71
 
        sys.exit(1)
72
 
    del parts[i:]
73
 
    parts.extend(['tags', relname])
74
 
    dsturl = SLASH.join(parts)
75
 
    return srcurl, dsturl
76
 
 
77
 
 
78
 
def do(cmd):
79
 
    proc = Popen(cmd.split(), stdout=PIPE, stderr=PIPE)
80
 
    stdout, stderr = proc.communicate()
81
 
    return stdout, stderr
82
 
 
83
 
 
84
 
def now():
85
 
    return time.strftime('%d-%b-%Y', time.localtime(time.time()))
86
 
 
87
 
 
88
 
def releasedir(tagname=None):
89
 
    tmpdir = tempfile.gettempdir()
90
 
    return os.path.join(tmpdir, 'mailman-' + tagname)
91
 
 
92
 
 
93
 
def tag2rel(tagname):
94
 
    return 'Release_' + tagname.replace('.', '_')
95
 
 
96
 
 
97
 
 
98
 
def tag_release(tagname):
99
 
    # Convert dots in tagname to underscores
100
 
    relname = tag2rel(tagname)
101
 
    # Calculate the 'tags' directory, which should be a sibling of the
102
 
    # 'branches' directory.
103
 
    srcurl, dsturl = calculate_urls(relname)
104
 
    print 'Tag url:', dsturl
105
 
    fd, msgfile = tempfile.mkstemp(text=True)
106
 
    try:
107
 
        os.close(fd)
108
 
        fp = open(msgfile, 'w')
109
 
        try:
110
 
            print >> fp, 'Tagging release', tagname
111
 
        finally:
112
 
            fp.close()
113
 
        do('svn cp %s %s -F %s' % (srcurl, dsturl, msgfile))
114
 
    finally:
115
 
        os.remove(msgfile)
116
 
 
117
 
 
118
 
 
119
 
def make_pkg(tagname, sign):
120
 
    reldir = releasedir(tagname)
121
 
    if os.path.exists(reldir):
122
 
        print >> sys.stderr, 'Release directory already exists:', reldir
123
 
        sys.exit(1)
124
 
    relname = tag2rel(tagname)
125
 
    srcurl, dsturl = calculate_urls(relname)
126
 
    print 'Exporting to release dir', reldir, '...'
127
 
    do('svn export %s %s' % (dsturl, reldir))
128
 
    if not os.path.exists(reldir):
129
 
        print >> sys.stderr, 'svn export failed:', dsturl
130
 
        sys.exit(1)
131
 
    curdir = os.getcwd()
132
 
    try:
133
 
        os.chdir(os.path.dirname(reldir))
134
 
        print 'Making tarball...'
135
 
        relname = 'mailman-' + tagname
136
 
        tarfile = relname + '.tgz'
137
 
        do('tar cvzf %s --exclude .svn %s' % (tarfile, relname))
138
 
        do('tar cvzf mailman-doc.tgz --exclude .svn mailman-doc')
139
 
        if sign:
140
 
            do('gpg -bas %s' % tarfile)
141
 
    finally:
142
 
        os.chdir(curdir)
143
 
 
144
 
 
145
 
 
146
 
VERSIONMARK = '<!-VERSION--->'
147
 
DATEMARK    = '<!-DATE--->'
148
 
 
149
 
 
150
 
def do_bump(newvers):
151
 
    print 'Doing bump...',
152
 
    for file in ('index.ht',):
153
 
        print '\t%s...' % file,
154
 
        fp = open(os.path.join('admin', 'www', file), 'r+')
155
 
        text = fp.read()
156
 
        parts = text.split(VERSIONMARK)
157
 
        parts[1] = newvers
158
 
        text = VERSIONMARK.join(parts)
159
 
        parts = text.split(DATEMARK)
160
 
        parts[1] = now()
161
 
        text = DATEMARK.join(parts)
162
 
        fp.seek(0)
163
 
        fp.write(text)
164
 
        fp.close()
165
 
    # hack the configure.in file
166
 
    print 'Version.py...',
167
 
    infp = open('Mailman/Version.py')
168
 
    outfp = open('Mailman/Version.py.new', 'w')
169
 
    matched = False
170
 
    cre = re.compile(r'^VERSION(?P<ws>[ \t]*)=')
171
 
    for line in infp:
172
 
        mo = cre.search(line)
173
 
        if matched or not mo:
174
 
            outfp.write(line)
175
 
        else:
176
 
            outfp.write('VERSION%s= "%s"\n' % (mo.group('ws'), newvers))
177
 
            matched = True
178
 
    if not matched:
179
 
        print >> sys.stderr, 'Error! VERSION line not found'
180
 
    infp.close()
181
 
    outfp.close()
182
 
    os.rename('Mailman/Version.py.new', 'Mailman/Version.py')
183
 
 
184
 
 
185
 
 
186
 
def parseargs():
187
 
    parser = optparse.OptionParser(version=__version__,
188
 
                                   usage="""\
189
 
%prog [options] tagname
190
 
 
191
 
Manage releases of Mailman.  tagname is used in the various commands above.
192
 
It should essentially be the version number for the release, and is
193
 
required.""")
194
 
    parser.add_option('-t', '--tag',
195
 
                      default=False, action='store_true', help="""\
196
 
Tag all release files with tagname.""")
197
 
    parser.add_option('-p', '--package',
198
 
                      default=False, action='store_true',
199
 
                      help='Create the distribution package.')
200
 
    parser.add_option('-b', '--bump',
201
 
                      default=False, action='store_true', help="""\
202
 
Bump the revision number in key files to tagname.  This is done by textual
203
 
substitution.""")
204
 
    parser.add_option('-s', '--sign',
205
 
                      default=False, action='store_true', help="""\
206
 
Sign the release.  gpg will prompt you for your passphrase.""")
207
 
    opts, args = parser.parse_args()
208
 
    if len(args) > 1:
209
 
        print >> sys.stderr, 'Unexpected arguments:', SPACE(args[1:])
210
 
        sys.exit(1)
211
 
    if len(args) < 1:
212
 
        print >> sys.stderr, 'Required tagname argument is missing'
213
 
        sys.exit(1)
214
 
    return parser, opts, args[0]
215
 
 
216
 
 
217
 
 
218
 
def main():
219
 
    parser, opts, tagname = parseargs()
220
 
 
221
 
    # Very important!!!
222
 
    omask = os.umask(0)
223
 
    try:
224
 
        if opts.bump:
225
 
            do_bump(tagname)
226
 
        if opts.tag:
227
 
            tag_release(tagname)
228
 
        if opts.package:
229
 
            make_pkg(tagname, opts.sign)
230
 
    finally:
231
 
        os.umask(omask)
232
 
 
233
 
 
234
 
 
235
 
if __name__ == '__main__':
236
 
    main()