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