#!/usr/local/bin/python # Copyright (c) 2007 Niall O'Higgins # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # changes.py: a program to parse the output of 'cvs log ' and print out the N most # recent changes. # requires python 2.5+ from datetime import datetime import copy import getopt import operator import os.path import sys state = 0 entries = [] n = 3 def usage(): print >> sys.stderr, "%s: [-n num entries]" %(sys.argv[0]) os._exit(1) try: opts, args = getopt.getopt(sys.argv[1:], "n:") except getopt.GetoptError: usage() for o, a in opts: if o == "-n": n = int(a) curfile = "" curentry = {} # little state machine for the parser, probably could be simplified. for line in sys.stdin: if state == 0: if line.startswith('RCS file:'): state = 1 continue if state == 1: if line.startswith('Working file:'): curfile = os.path.basename(line.split()[2].strip()) state = 2 continue if state == 2: if line.startswith('description:'): state = 3 continue if state == 3: if line.strip() == '----------------------------': curentry['name'] = curfile curentry['text'] = "" state = 4 continue elif line.strip() == '=============================================================================': state = 0 continue if state == 4: if line.strip() == '=============================================================================': state = 0 continue elif line.strip() != '----------------------------': if line.startswith('date: '): s = line.split() stamp = "%s %s" %(s[1], s[2].rstrip(';')) # could do some ugly stuff to make this work pre 2.5 curentry['dt'] = datetime.strptime(stamp, "%Y/%m/%d %H:%M:%S") curentry['text'] = "%s%s" %(curentry['text'], line) continue else: entries.append(copy.copy(curentry)) curentry = {} state = 3 continue entries.sort(key=operator.itemgetter('dt'), reverse=True) for i in range(0, n): print entries[i]['name'] print entries[i]['text'].replace('<', '<').replace('>', '>')