Guido van Rossum | f06ee5f | 1996-11-27 19:52:01 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Guido van Rossum | db9c054 | 1996-07-30 19:05:41 +0000 | [diff] [blame] | 2 | |
| 3 | """Turn a pile of RCS log output into ChangeLog file entries. |
| 4 | |
| 5 | """ |
| 6 | |
| 7 | import sys |
| 8 | import string |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 9 | import re |
Guido van Rossum | db9c054 | 1996-07-30 19:05:41 +0000 | [diff] [blame] | 10 | import getopt |
| 11 | import time |
| 12 | |
| 13 | def main(): |
| 14 | args = sys.argv[1:] |
| 15 | opts, args = getopt.getopt(args, 'p:') |
| 16 | prefix = '' |
| 17 | for o, a in opts: |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 18 | if p == '-p': prefix = a |
Guido van Rossum | db9c054 | 1996-07-30 19:05:41 +0000 | [diff] [blame] | 19 | |
| 20 | f = sys.stdin |
| 21 | allrevs = [] |
| 22 | while 1: |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 23 | file = getnextfile(f) |
| 24 | if not file: break |
| 25 | revs = [] |
| 26 | while 1: |
| 27 | rev = getnextrev(f, file) |
| 28 | if not rev: |
| 29 | break |
| 30 | revs.append(rev) |
| 31 | if revs: |
| 32 | allrevs[len(allrevs):] = revs |
Guido van Rossum | db9c054 | 1996-07-30 19:05:41 +0000 | [diff] [blame] | 33 | allrevs.sort() |
| 34 | allrevs.reverse() |
| 35 | for rev in allrevs: |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 36 | formatrev(rev, prefix) |
Guido van Rossum | db9c054 | 1996-07-30 19:05:41 +0000 | [diff] [blame] | 37 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 38 | parsedateprog = re.compile( |
| 39 | '^date: ([0-9]+)/([0-9]+)/([0-9]+) ' + |
| 40 | '([0-9]+):([0-9]+):([0-9]+); author: ([^ ;]+)') |
Guido van Rossum | db9c054 | 1996-07-30 19:05:41 +0000 | [diff] [blame] | 41 | |
| 42 | authormap = { |
| 43 | 'guido': 'Guido van Rossum <guido@cnri.reston.va.us>', |
| 44 | 'jack': 'Jack Jansen <jack@cwi.nl>', |
| 45 | 'sjoerd': 'Sjoerd Mullender <sjoerd@cwi.nl>', |
| 46 | } |
| 47 | |
| 48 | def formatrev(rev, prefix): |
| 49 | dateline, file, revline, log = rev |
| 50 | if parsedateprog.match(dateline) >= 0: |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 51 | fields = parsedateprog.group(1, 2, 3, 4, 5, 6) |
| 52 | author = parsedateprog.group(7) |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 53 | if author in authormap: author = authormap[author] |
| 54 | tfields = list(map(string.atoi, fields)) + [0, 0, 0] |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 55 | tfields[5] = tfields[5] - time.timezone |
| 56 | t = time.mktime(tuple(tfields)) |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 57 | print(time.ctime(t), '', author) |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 58 | words = string.split(log) |
| 59 | words[:0] = ['*', prefix + file + ':'] |
| 60 | maxcol = 72-8 |
| 61 | col = maxcol |
| 62 | for word in words: |
| 63 | if col > 0 and col + len(word) >= maxcol: |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 64 | print() |
| 65 | print('\t' + word, end=' ') |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 66 | col = -1 |
| 67 | else: |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 68 | print(word, end=' ') |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 69 | col = col + 1 + len(word) |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 70 | print() |
| 71 | print() |
Guido van Rossum | db9c054 | 1996-07-30 19:05:41 +0000 | [diff] [blame] | 72 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 73 | startprog = re.compile("^Working file: (.*)$") |
Guido van Rossum | db9c054 | 1996-07-30 19:05:41 +0000 | [diff] [blame] | 74 | |
| 75 | def getnextfile(f): |
| 76 | while 1: |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 77 | line = f.readline() |
| 78 | if not line: return None |
| 79 | if startprog.match(line) >= 0: |
| 80 | file = startprog.group(1) |
| 81 | # Skip until first revision |
| 82 | while 1: |
| 83 | line = f.readline() |
| 84 | if not line: return None |
| 85 | if line[:10] == '='*10: return None |
| 86 | if line[:10] == '-'*10: break |
| 87 | ## print "Skipped", line, |
| 88 | return file |
| 89 | ## else: |
| 90 | ## print "Ignored", line, |
Guido van Rossum | db9c054 | 1996-07-30 19:05:41 +0000 | [diff] [blame] | 91 | |
| 92 | def getnextrev(f, file): |
| 93 | # This is called when we are positioned just after a '---' separator |
| 94 | revline = f.readline() |
| 95 | dateline = f.readline() |
| 96 | log = '' |
| 97 | while 1: |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 98 | line = f.readline() |
| 99 | if not line: break |
| 100 | if line[:10] == '='*10: |
| 101 | # Ignore the *last* log entry for each file since it |
| 102 | # is the revision since which we are logging. |
| 103 | return None |
| 104 | if line[:10] == '-'*10: break |
| 105 | log = log + line |
Guido van Rossum | db9c054 | 1996-07-30 19:05:41 +0000 | [diff] [blame] | 106 | return dateline, file, revline, log |
| 107 | |
| 108 | if __name__ == '__main__': |
| 109 | main() |