#!/usr/bin/python # # Copyright (C) 2006, Adam Cecile # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # # This Subversion post-commit hook script is meant to create sources tarball # for releases. # # It should be called from the 'post-commit' script in Subversion, such as # via: # # REPOS="${1}" # REV="${2}" # LOG=`/usr/bin/svnlook log -r ${REV} ${REPOS}` # SOFT_NAME="test" # SVN_URL="http://test.le-vert.net/svn" # SVN_TAGS_BASE="/tags/" # SVN_TAGS_APPEND="${SOFTNAME}" # TARBALL_DIR="/data/repos/test/tarballs/" # # /usr/bin/python /data/trac/scripts/create-release-tarball \ # "${LOG}" \ # "${SOFT_NAME}" \ # "${SVN_URL}" \ # "${SVN_TAGS_BASE}" \ # "${SVN_TAGS_APPEND}" \ # "${TARBALL_DIR}" # # It searches commit messages for text like (Release: x.y.z) or # (release x.yz.y.v) in example. # # EXPLAINATION OF THE EXAMPLE ABOVE : # # If you add (Release: 0.1.1) to you commit comment, this hook will : # 1. svn export http://test.le-vert.net/svn/tags/0.1.1/test \ # /tmp/test-0.1.1+"randomsuffix" # 2. Create a tarball named test-0.1.1.tar.gz # 3. Move the tarball to /data/repos/test/tarballs/ # # # I hope you will like my hook, even I don't at all how to write real # Python code... Enjoy anyway ;-) # Modules imports import pysvn import tempfile import os import sys import re # Get arguments svn_log= sys.argv[1] soft_name = sys.argv[2] svn_url = sys.argv[3] svn_tags_base = sys.argv[4] svn_tags_append = sys.argv[5] tarball_dir = sys.argv[6] # Ok, this is the interresting point. # We're looking for the release pattern in svn commit comment. commandPattern = re.compile(r'\([rR]elease:{0,1} +([0-9.]+)\)') if commandPattern.search(svn_log): # Get release number release_nb = commandPattern.findall(svn_log)[0] print 'Release pattern found ! Creating tarball for version '+release_nb+'.' # Create an unique temp directory svn_workdir = tempfile.mkdtemp('', soft_name+'-'+release_nb+'_') print "Working in " + svn_workdir # Export released sourcecode client = pysvn.Client() client.export(svn_url+'/'+svn_tags_base+'/'+release_nb+'/'+svn_tags_append, svn_workdir+'/'+soft_name+'-'+release_nb) # Move into svn_workdir os.chdir(svn_workdir) # Create the tar.gz cmd line, then execute it targzcmd='tar cvzf '+soft_name+'-'+release_nb+'.tar.gz '+soft_name+'-'+release_nb+'/ >/dev/null' print "Running "+targzcmd os.system(targzcmd) # Create the tar.bz2 cmd line, then execute it tarbz2cmd='tar cvjf '+soft_name+'-'+release_nb+'.tar.bz2 '+soft_name+'-'+release_nb+'/ >/dev/null' print "Running "+tarbz2cmd os.system(tarbz2cmd) # Move tarball gz into tarball_dir movgzcmd = 'mv '+svn_workdir+'/'+soft_name+'-'+release_nb+'.tar.gz '+tarball_dir print "Running "+movgzcmd os.system(movgzcmd) # Move tarball bz2 into tarball_dir movbz2cmd = 'mv '+svn_workdir+'/'+soft_name+'-'+release_nb+'.tar.bz2 '+tarball_dir print "Running "+movbz2cmd os.system(movbz2cmd) # Clean svn_workdir cleancmd = 'rm -rf '+svn_workdir os.system(cleancmd) else: # Skip and exit print 'No release pattern found. Skipping this hook.' sys.exit(0)