hgbook

annotate en/fblinks @ 573:40025381bded

Get the copyright years right
author Bryan O'Sullivan <bos@serpentine.com>
date Mon Mar 09 23:42:31 2009 -0700 (2009-03-09)
parents ce3339dbeb6f
children
rev   line source
bos@18 1 #!/usr/bin/python
bos@18 2
bos@18 3 import errno
bos@18 4 import os
bos@18 5 import re
bos@18 6 import sys
bos@18 7
bos@21 8 hg_id = sys.argv[1]
bos@18 9
bos@18 10 dest_dir = sys.argv[2]
bos@18 11
bos@21 12 empty_re = re.compile(r'^\s*$')
bos@21 13 line_re = re.compile(r'^(\w+)(.*)')
bos@18 14
bos@18 15 try:
bos@18 16 os.makedirs(dest_dir)
bos@18 17 except OSError, err:
bos@18 18 if err.errno != errno.EEXIST:
bos@18 19 raise
bos@18 20
bos@23 21 def feedback(name, text, ctx_id):
bos@23 22 return r'\marginpar{\scriptsize \href{http://demesne:8000/book/feedback/submit/%s/%s/%d/}{Feedback}}' % (hg_id, name, ctx_id)
bos@21 23
bos@21 24 ctxs = {}
bos@21 25 try:
bos@21 26 cfp = open(os.path.join(dest_dir, 'rev-' + hg_id + '.ctx'), 'r+')
bos@21 27 for line in cfp:
bos@21 28 f, l, c = line.split(':', 2)
bos@21 29 ctxs[(f, int(l))] = c.strip()
bos@21 30 except IOError, err:
bos@21 31 if err.errno != errno.ENOENT: raise
bos@21 32 cfp = open(os.path.join(dest_dir, 'rev-' + hg_id + '.ctx'), 'w+')
bos@21 33
bos@21 34 changes = 0
bos@18 35
bos@18 36 for name in sys.argv[3:]:
bos@18 37 if not name.endswith('.tex'):
bos@18 38 continue
bos@18 39 dest_name = os.path.join(dest_dir, name)
bos@18 40 ifp = open(name)
bos@18 41 ofp = open(dest_name, 'w')
bos@18 42 new_par = True
bos@18 43 line_num = 0
bos@23 44 par_num = 0
bos@18 45 for line in ifp:
bos@18 46 line_num += 1
bos@18 47 if new_par:
bos@18 48 m = line_re.match(line)
bos@18 49 if m:
bos@23 50 par_num += 1
bos@21 51 ls = line.strip()
bos@23 52 if ctxs.get((name, par_num)) != ls:
bos@23 53 ctxs[(name, par_num)] = ls
bos@21 54 changes += 1
bos@23 55 line = m.group(1) + feedback(name, line, par_num) + m.group(2)
bos@18 56 new_par = False
bos@18 57 elif not line.strip():
bos@18 58 new_par = True
bos@18 59 ofp.write(line)
bos@21 60
bos@21 61 if changes:
bos@21 62 cfp.seek(0)
bos@21 63 print '%s: %d changes' % (cfp.name, changes)
bos@21 64 ctxs = ctxs.items()
bos@21 65 ctxs.sort()
bos@21 66 for ((file, line), content) in ctxs:
bos@21 67 cfp.write('%s:%d: %s\n' % (file, line, content))