comparison en/fblinks @ 21:ce3339dbeb6f

Get beta feedback stuff into better shape.
author Bryan O'Sullivan <bos@serpentine.com>
date Wed, 05 Jul 2006 00:14:15 -0700
parents e6f4088ebe52
children 9457add294b8
comparison
equal deleted inserted replaced
18:e6f4088ebe52 21:ce3339dbeb6f
3 import errno 3 import errno
4 import os 4 import os
5 import re 5 import re
6 import sys 6 import sys
7 7
8 hg_id = sys.argv[1][:12] 8 hg_id = sys.argv[1]
9 9
10 dest_dir = sys.argv[2] 10 dest_dir = sys.argv[2]
11 11
12 empty_re = re.compile('^\s*$') 12 empty_re = re.compile(r'^\s*$')
13 line_re = re.compile('^(\w+)(.*)') 13 line_re = re.compile(r'^(\w+)(.*)')
14 14
15 try: 15 try:
16 os.makedirs(dest_dir) 16 os.makedirs(dest_dir)
17 except OSError, err: 17 except OSError, err:
18 if err.errno != errno.EEXIST: 18 if err.errno != errno.EEXIST:
19 raise 19 raise
20 20
21 def feedback(name, text, line): 21 def feedback(name, text, line):
22 return r'\marginpar{\scriptsize \href{http://www.sourcecontrol.org/book/feedback.cgi?id=%s&file=%s&line=%d}{Feedback?}}' % (hg_id, name, line) 22 return r'\marginpar{\scriptsize \href{http://demesne:8000/book/feedback/submit/%s/%s/%d/}{Feedback}}' % (hg_id, name, line)
23
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+')
33
34 changes = 0
23 35
24 for name in sys.argv[3:]: 36 for name in sys.argv[3:]:
25 if not name.endswith('.tex'): 37 if not name.endswith('.tex'):
26 continue 38 continue
27 dest_name = os.path.join(dest_dir, name) 39 dest_name = os.path.join(dest_dir, name)
32 for line in ifp: 44 for line in ifp:
33 line_num += 1 45 line_num += 1
34 if new_par: 46 if new_par:
35 m = line_re.match(line) 47 m = line_re.match(line)
36 if m: 48 if m:
49 ls = line.strip()
50 if ctxs.get((name, line_num)) != ls:
51 ctxs[(name, line_num)] = ls
52 changes += 1
37 line = m.group(1) + feedback(name, line, line_num) + m.group(2) 53 line = m.group(1) + feedback(name, line, line_num) + m.group(2)
38 new_par = False 54 new_par = False
39 elif not line.strip(): 55 elif not line.strip():
40 new_par = True 56 new_par = True
41 ofp.write(line) 57 ofp.write(line)
58
59 if changes:
60 cfp.seek(0)
61 print '%s: %d changes' % (cfp.name, changes)
62 ctxs = ctxs.items()
63 ctxs.sort()
64 for ((file, line), content) in ctxs:
65 cfp.write('%s:%d: %s\n' % (file, line, content))