Index: CVSROOT/cvs-log.py =================================================================== diff -u --- CVSROOT/cvs-log.py (revision 0) +++ CVSROOT/cvs-log.py (revision ec5f7d6f94bb94f81d73f47aacb405ae5e98af34) @@ -0,0 +1,136 @@ +#!/usr/bin/python +# +# Simple cvs commit logger/mailer. Many ideas copyied from +# original 'log.pl' scripts that ships with CVS under 'contrib' +# +# Copyright (C) 2002 Sam Clegg +# +# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $superduper: cvs-log.py,v 1.5 2002/05/03 06:31:51 samc Exp $ +""" +To use this script: + +1. add cvs-log.py to your CVSROOT + +2. add the following line to your CVSROOT/loginfo: + $CVSROOT/CVSROOT/cvs-log.py -f -m %{svV} + +3. add the cvs-log.py to CVSROOT/checkoutlist. + +4. checkin all in again. +""" + +import os +import getopt +import time +import sys + +name = 'cvs-log.py' +version = '0.1' +url = 'http://colis03.elceap.mq.edu.au/cgi-bin/viewcvs.cgi/cvs-log/' + +viewcvs_url = 'http://colis03.elceap.mq.edu.au/cgi-bin/viewcvs.cgi' +logfile = None +users = None +mailpipe = None +login = None + +def print_usage(): + print >> sys.stderr, 'Usage: log.py [-m address] [-f logfile] "module file" ...' + print >> sys.stderr, '' + print >> sys.stderr, '\t-m \t- email address(s) to mail log to.' + print >> sys.stderr, '\t-f \t- logfile to append to.' + +# for some reason os.getlogin throws an exception we are launched by cvs. +try: + login = os.getlogin() +except OSError: + login = str(os.getuid()) + +# parse command line arguments +opts = [] +args = [] +try: + opts, args = getopt.getopt(sys.argv[1:], 'f:m:') +except getopt.GetoptError: + print_usage() + sys.exit(-1) + +for o, a in opts: + if o == '-f': + logfile = a + if o == '-m': + users = a + +# check that we have either a log file or and email +if not (logfile or users): + print_usage() + sys.exit(-1) + +# the first part of the single arg is the module location relative to $CVSROOT +files = args[0].split() +modulepath = files[0] + +# the rest are files that have been changed +files = files[1:] + +if logfile: + log = open(logfile, 'a') + +# open pipe into sendmail +if users: + mailcmd = 'mail -s "CVS update: %s" %s' % (modulepath, users) + mailpipe = os.popen(mailcmd, 'w') + +# write out the log header +if logfile: + time.strftime('%a, %d %b %Y %H:%M %Z') + log.write("Date:\t%s\n" % time.strftime('%a, %d %b %Y %H:%M %Z')) + log.write('Author:\t%s\n\n' % login) + +if mailpipe: + mailpipe.write("Date:\t%s\n" % time.strftime('%a, %d %b %Y %H:%M %Z')) + mailpipe.write('Author:\t%s\n\n' % login) + +# write out the log message that comes in on stdin. +line = sys.stdin.readline() +while line: + if logfile: log.write(line) + if mailpipe: mailpipe.write(line) + line = sys.stdin.readline() + +# add viewcvs links if we have a url +if (viewcvs_url): + if logfile: log.write("Web Diffs:\n") + if mailpipe: mailpipe.write("Web Diffs:\n") + for file in files: + # special cases when directories are added/imported + if file in ['Imported', 'sources', '-', 'New', 'directory']: continue + file, version, lastversion = file.split(',') + + # When files are added or removed one of the verions is "NONE" + if version == "NONE" or lastversion == "NONE": continue + url = '%s/%s/%s.diff?r1=%s&r2=%s' % (viewcvs_url, modulepath, file, lastversion, version) + if logfile: log.write(' File: %s\n Diff: %s\n\n' % (file, url)) + if mailpipe: mailpipe.write(' File: %s\n Diff: %s\n\n' % (file, url)) + +if logfile: log.write("\n****************************************\n") +if logfile: log.close() +if mailpipe: mailpipe.write("This message was generated by %s v%s (%s)" % (name, version, url)) +if mailpipe: mailpipe.close() + +sys.exit(0) +