From e6d361fc922ed5cc408a2c56b735f0b7d4e27407 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 17 Jun 2012 10:30:17 -0400 Subject: [PATCH] release: Revamp to use subprocess instead of os.system Signed-off-by: James McCoy --- sandbox/release.py | 67 +++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/sandbox/release.py b/sandbox/release.py index e713ea7bb..92fc70ec7 100644 --- a/sandbox/release.py +++ b/sandbox/release.py @@ -4,6 +4,7 @@ import os import re import sys import shutil +import subprocess from optparse import OptionParser @@ -13,6 +14,7 @@ def firstLines(filename, n): while n: n -= 1 lines.append(fd.readline().rstrip('\r\n')) + fd.close() return lines def firstLine(filename): @@ -22,23 +24,29 @@ def error(s): sys.stderr.write(s+'\n') sys.exit(-1) -def system(sh, errmsg=None): +def system(sh, errmsg=None, **kwargs): if errmsg is None: - errmsg = repr(sh) - ret = os.system(sh) + if isinstance(sh, basestring): + errmsg = repr(sh) + else: + errmsg = repr(' '.join(sh)) + ret = subprocess.call(sh, **kwargs) if ret: error(errmsg + ' (error code: %s)' % ret) def checkGitRepo(): system('test "$(git rev-parse --is-inside-work-tree)" = "true"', - 'Must be run from a git checkout.') + 'Must be run from a git checkout.', + shell=True) system('test "$(git rev-parse --show-cdup >/dev/null)" = ""', - 'Must be run from the top-level directory of the git checkout.') + 'Must be run from the top-level directory of the git checkout.', + shell=True) system('git rev-parse --verify HEAD >/dev/null ' '&& git update-index --refresh' '&& git diff-files --quiet' '&& git diff-index --cached --quiet HEAD --', - 'Your tree is unclean. Can\'t run from here.') + 'Your tree is unclean. Can\'t run from here.', + shell=True) if __name__ == '__main__': usage = 'usage: %prog [options] ' @@ -72,8 +80,8 @@ if __name__ == '__main__': ' Change to an appropriate directory or remove the supybot ' 'directory to continue.') print 'Checking out fresh tree from git.' - system('git clone -b %s git+ssh://%s@supybot.git.sourceforge.net/gitroot/supybot' - % (branch, u)) + system(['git', 'clone', '-b', branch, + 'git+ssh://%s@supybot.git.sourceforge.net/gitroot/supybot' % u]) os.chdir('supybot') print 'Checking RELNOTES version line.' @@ -90,36 +98,45 @@ if __name__ == '__main__': print 'Updating version in version files.' versionFiles = ['src/version.py'] for fn in versionFiles: - sh = 'perl -pi -e "s/^version\s*=.*/version = \'%s\'/" %s' % (v, fn) + sh = ['perl', '-pi', '-e', 's/^version\s*=.*/version = \'%s\'/' % v, fn] system(sh, 'Error changing version in %s' % fn) - system('git commit %s -m \'Updated to %s.\' %s' - % (sign, v, ' '.join(versionFiles))) + commit = ['git', 'commit'] + if sign: + commit.append('-s') + system(commit + ['-m', 'Updated to %s.' % v] + versionFiles) print 'Tagging release.' - system('git tag %s -m "Release %s" %s' % (sign or '-a', v, v)) + tag = ['git', 'tag'] + if sign: + tag.append('-s') + system(tag + ['-m', "Release %s" % v, 'v%s' % v]) 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) - system('git commit %s -m \'Updated to %s+git.\' %s' - % (sign, v, ' '.join(versionFiles))) + system(['perl', '-pi', '-e', + 's/^version\s*=.*/version = \'%s+git\'/' % v, fn], + 'Error changing version in %s' % fn) + system(commit + ['-m', 'Updated to %s+git.' % v] + versionFiles) if not dryrun: print 'Pushing commits and tag.' - system('git push origin %s' % branch) - system('git push --tags') + system(['git', 'push', 'origin', branch]) + system(['git', 'push', '--tags']) + archive = ['git', 'archive', '--prefix=Supybot-%s/' % v] print 'Creating tarball (gzip).' - system('git archive --prefix=Supybot-%s/ --format=tar %s ' - '| gzip -c >../Supybot-%s.tar.gz' % (v, v, v)) + system(archive + ['-o', '../Supybot-%s.tar.gz' % v, + '--format=tgz', 'v%s' % v]) + + system(['git', 'config', 'tar.bz2.command', 'bzip2 -c']) + print 'Creating tarball (bzip2).' - system('git archive --prefix=Supybot-%s/ --format=tar %s ' - '| bzip2 -c >../Supybot-%s.tar.bz2' % (v, v, v)) + system(archive + ['-o', '../Supybot-%s.tar.bz2' % v, + '--format=bz2', 'v%s' % v]) + print 'Creating zip.' - system('git archive --prefix=Supybot-%s/ --format=zip %s ' - '>../Supybot-%s.zip' % (v, v, v)) + system(archive + ['-o', '../Supybot-%s.zip' % v, + '--format=zip', 'v%s' % v]) os.chdir('..') shutil.rmtree('supybot')