2005-05-02 19:39:12 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
def firstLines(filename, n):
|
|
|
|
fd = file(filename)
|
|
|
|
lines = []
|
|
|
|
while n:
|
|
|
|
n -= 1
|
|
|
|
lines.append(fd.readline().rstrip('\r\n'))
|
|
|
|
return lines
|
|
|
|
|
|
|
|
def firstLine(filename):
|
|
|
|
return firstLines(filename, 1)[0]
|
|
|
|
|
|
|
|
def error(s):
|
|
|
|
sys.stderr.write(s+'\n')
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
def system(sh, errmsg=None):
|
|
|
|
if errmsg is None:
|
|
|
|
errmsg = repr(sh)
|
|
|
|
ret = os.system(sh)
|
|
|
|
if ret:
|
|
|
|
error(errmsg + ' (error code: %s)' % ret)
|
|
|
|
|
2009-02-27 21:06:04 +01:00
|
|
|
def usage():
|
2009-05-18 08:55:23 +02:00
|
|
|
error('Usage: %s [-s|-n] <sf username> <version>\nSpecify -s to pass it on '
|
|
|
|
'to the relevant git commands.\nSpecify -n to perform a dry-run '
|
|
|
|
'release. No commits or tags are pushed and no files are uploaded.'
|
|
|
|
'\nMust be called from a git checkout.'
|
2009-03-16 22:33:34 +01:00
|
|
|
% sys.argv[0])
|
|
|
|
|
|
|
|
def checkGitRepo():
|
2009-05-18 09:02:52 +02:00
|
|
|
system('test "$(git rev-parse --is-inside-work-tree)" = "true"',
|
2009-03-16 22:33:34 +01:00
|
|
|
'Must be run from a git checkout.')
|
|
|
|
system('test "$(git rev-parse --show-cdup >/dev/null)" = ""',
|
|
|
|
'Must be run from the top-level directory of the git checkout.')
|
|
|
|
system('git rev-parse --verify HEAD >/dev/null '
|
|
|
|
'&& git update-index --refresh'
|
|
|
|
'&& git diff-files --quiet'
|
2009-05-18 09:02:52 +02:00
|
|
|
'&& git diff-index --cached --quiet HEAD --',
|
2009-03-16 22:33:34 +01:00
|
|
|
'Your tree is unclean. Can\'t run from here.')
|
2009-02-27 21:06:04 +01:00
|
|
|
|
2005-05-02 19:39:12 +02:00
|
|
|
if __name__ == '__main__':
|
2009-05-18 08:55:23 +02:00
|
|
|
if len(sys.argv) < 3 or len(sys.argv) > 5:
|
2009-02-27 21:06:04 +01:00
|
|
|
usage()
|
|
|
|
|
2009-03-16 22:33:34 +01:00
|
|
|
checkGitRepo()
|
|
|
|
|
2009-02-27 21:06:04 +01:00
|
|
|
sign = ''
|
2009-05-18 08:55:23 +02:00
|
|
|
dryrun = False
|
|
|
|
while len(sys.argv) > 3:
|
2009-02-27 21:06:04 +01:00
|
|
|
if sys.argv[1] == '-s':
|
|
|
|
sign = '-s'
|
|
|
|
sys.argv.pop(1)
|
2009-05-18 08:55:23 +02:00
|
|
|
elif sys.argv[1] == '-n':
|
|
|
|
dryrun = True
|
|
|
|
sys.argv.pop(1)
|
2009-02-27 21:06:04 +01:00
|
|
|
else:
|
|
|
|
usage()
|
2005-05-02 19:39:12 +02:00
|
|
|
|
|
|
|
print 'Check version string for validity.'
|
|
|
|
(u, v) = sys.argv[1:]
|
2009-05-25 19:32:02 +02:00
|
|
|
if not re.match(r'^\d+\.\d+\.\d+(\.\d+)?\w*$', v):
|
2005-05-02 19:39:12 +02:00
|
|
|
error('Invalid version string: '
|
|
|
|
'must be of the form MAJOR.MINOR.PATCHLEVEL.')
|
|
|
|
|
|
|
|
if os.path.exists('supybot'):
|
|
|
|
error('I need to make the directory "supybot" but it already exists.'
|
2009-02-27 21:06:04 +01:00
|
|
|
' Change to an appropriate directory or remove the supybot '
|
2005-05-02 19:39:12 +02:00
|
|
|
'directory to continue.')
|
2009-02-27 21:06:04 +01:00
|
|
|
print 'Checking out fresh tree from git.'
|
2009-05-18 09:07:27 +02:00
|
|
|
system('git clone git+ssh://%s@supybot.git.sourceforge.net/gitroot/supybot'
|
|
|
|
% u)
|
2005-05-02 19:39:12 +02:00
|
|
|
os.chdir('supybot')
|
|
|
|
|
|
|
|
print 'Checking RELNOTES version line.'
|
|
|
|
if firstLine('RELNOTES') != 'Version %s' % v:
|
|
|
|
error('Invalid first line in RELNOTES.')
|
|
|
|
|
|
|
|
print 'Checking ChangeLog version line.'
|
|
|
|
(first, _, third) = firstLines('ChangeLog', 3)
|
2009-02-27 21:06:04 +01:00
|
|
|
if not re.match(r'^20\d\d-\d{2}-\d{2}\s+\w+.*<\S+@\S+>$', first):
|
2005-05-02 19:39:12 +02:00
|
|
|
error('Invalid first line in ChangeLog.')
|
|
|
|
if not re.match(r'^\t\* Version %s!$' % v, third):
|
|
|
|
error('Invalid third line in ChangeLog.')
|
|
|
|
|
|
|
|
print 'Updating version in version files.'
|
|
|
|
versionFiles = ('src/conf.py', 'scripts/supybot', 'setup.py')
|
|
|
|
for fn in versionFiles:
|
|
|
|
sh = 'perl -pi -e "s/^version\s*=.*/version = \'%s\'/" %s' % (v, fn)
|
|
|
|
system(sh, 'Error changing version in %s' % fn)
|
2009-05-18 09:07:27 +02:00
|
|
|
system('git commit %s -m \'Updated to %s.\' %s'
|
2009-02-27 21:06:04 +01:00
|
|
|
% (sign, v, ' '.join(versionFiles)))
|
2005-05-02 19:39:12 +02:00
|
|
|
|
|
|
|
print 'Tagging release.'
|
2009-03-16 22:33:34 +01:00
|
|
|
system('git tag %s -m "Release %s" %s' % (sign or '-a', v, v))
|
|
|
|
|
2009-03-17 04:44:14 +01:00
|
|
|
print 'Committing %s+git to version files.' % v
|
|
|
|
for fn in versionFiles:
|
|
|
|
sh = 'perl -pi -e "s/^version\s*=.*/version = \'%s\'/" %s' % \
|
|
|
|
(v + '+git', fn)
|
|
|
|
system(sh, 'Error changing version in %s' % fn)
|
2009-05-18 09:30:54 +02:00
|
|
|
system('git commit %s -m \'Updated to %s+git.\' %s'
|
2009-03-17 04:44:14 +01:00
|
|
|
% (sign, v, ' '.join(versionFiles)))
|
|
|
|
|
2009-05-18 08:55:23 +02:00
|
|
|
if not dryrun:
|
|
|
|
print 'Pushing commits and tag.'
|
|
|
|
system('git push origin master')
|
|
|
|
system('git push --tags')
|
2005-05-02 19:39:12 +02:00
|
|
|
|
|
|
|
print 'Creating tarball (gzip).'
|
2009-03-17 04:44:14 +01:00
|
|
|
system('git archive --prefix=Supybot-%s/ --format=tar %s '
|
|
|
|
'| gzip -c >../Supybot-%s.tar.gz' % (v, v, v))
|
2005-05-02 19:39:12 +02:00
|
|
|
print 'Creating tarball (bzip2).'
|
2009-03-17 04:44:14 +01:00
|
|
|
system('git archive --prefix=Supybot-%s/ --format=tar %s '
|
|
|
|
'| bzip2 -c >../Supybot-%s.tar.bz2' % (v, v, v))
|
2005-05-02 19:39:12 +02:00
|
|
|
print 'Creating zip.'
|
2009-03-17 04:44:14 +01:00
|
|
|
system('git archive --prefix=Supybot-%s/ --format=zip %s '
|
2009-05-18 09:31:16 +02:00
|
|
|
'>../Supybot-%s.zip' % (v, v, v))
|
2009-03-17 04:44:14 +01:00
|
|
|
|
|
|
|
os.chdir('..')
|
|
|
|
shutil.rmtree('supybot')
|
2005-05-02 19:39:12 +02:00
|
|
|
|
2009-05-18 08:55:23 +02:00
|
|
|
if not dryrun:
|
|
|
|
print 'Uploading package files to upload.sf.net.'
|
|
|
|
system('scp Supybot-%s.tar.gz Supybot-%s.tar.bz2 Supybot-%s.zip '
|
|
|
|
'%s@frs.sourceforge.net:uploads' % (v, v, v, u))
|
2009-02-27 21:06:04 +01:00
|
|
|
|
2009-05-18 08:55:23 +02:00
|
|
|
print 'Copying new version.txt over to project webserver.'
|
|
|
|
system('echo %s > version.txt' % v)
|
2009-05-18 09:56:05 +02:00
|
|
|
system('scp version.txt %s@web.sf.net:/home/groups/s/su/supybot/htdocs'
|
|
|
|
%u)
|
2009-05-18 08:55:23 +02:00
|
|
|
system('rm version.txt')
|
2005-05-02 19:39:12 +02:00
|
|
|
|
|
|
|
# print 'Generating documentation.'
|
|
|
|
# # docFiles is in the format {directory: files}
|
|
|
|
# docFiles = {'.': ('README', 'INSTALL', 'ChangeLog'),
|
|
|
|
# 'docs': ('config.html', 'CAPABILITIES', 'commands.html',
|
|
|
|
# 'CONFIGURATION', 'FAQ', 'GETTING_STARTED',
|
|
|
|
# 'INTERFACES', 'OVERVIEW', 'PLUGIN-EXAMPLE',
|
|
|
|
# 'plugins', 'plugins.html', 'STYLE'),
|
|
|
|
# }
|
|
|
|
# system('python scripts/supybot-plugin-doc')
|
|
|
|
# pwd = os.getcwd()
|
|
|
|
# os.chmod('docs/plugins', 0775)
|
|
|
|
# sh = 'tar rf %s/docs.tar %%s' % pwd
|
|
|
|
# for (dir, L) in docFiles.iteritems():
|
|
|
|
# os.chdir(os.path.join(pwd, dir))
|
|
|
|
# system(sh % ' '.join(L))
|
|
|
|
# os.chdir(pwd)
|
|
|
|
# system('bzip2 docs.tar')
|
|
|
|
#
|
|
|
|
# print 'Uploading documentation to webspace.'
|
|
|
|
# system('scp docs.tar.bz2 %s@supybot.sf.net:/home/groups/s/su/supybot'
|
|
|
|
# '/htdocs/docs/.' % u)
|
|
|
|
# system('ssh %s@supybot.sf.net "cd /home/groups/s/su/supybot/htdocs/docs; '
|
|
|
|
# 'tar jxf docs.tar.bz2"' % u)
|
|
|
|
#
|
|
|
|
# print 'Cleaning up generated documentation.'
|
|
|
|
# shutil.rmtree('docs/plugins')
|
|
|
|
# configFiles = ('docs/config.html', 'docs/plugins.html',
|
|
|
|
# 'docs/commands.html', 'docs.tar.bz2', 'test-conf',
|
|
|
|
# 'test-data', 'test-logs', 'tmp')
|
|
|
|
# for fn in configFiles:
|
|
|
|
# os.remove(fn)
|
|
|
|
|
|
|
|
# This is the part where we do our release on Freshmeat using XMLRPC and
|
|
|
|
# <gasp> ESR's software to do it: http://freshmeat.net/p/freshmeat-submit/
|