/Demo/pdist/makechangelog.py

http://unladen-swallow.googlecode.com/ · Python · 109 lines · 87 code · 11 blank · 11 comment · 26 complexity · 19ee44f886988b7ac0274ed2df3e8925 MD5 · raw file

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