Mercurial > hgbook
comparison en/fblinks @ 18:e6f4088ebe52
Generate a PDF file with a feedback link on each paragraph.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Tue, 04 Jul 2006 16:41:31 -0700 |
parents | |
children | ce3339dbeb6f |
comparison
equal
deleted
inserted
replaced
17:2668e15c76e9 | 18:e6f4088ebe52 |
---|---|
1 #!/usr/bin/python | |
2 | |
3 import errno | |
4 import os | |
5 import re | |
6 import sys | |
7 | |
8 hg_id = sys.argv[1][:12] | |
9 | |
10 dest_dir = sys.argv[2] | |
11 | |
12 empty_re = re.compile('^\s*$') | |
13 line_re = re.compile('^(\w+)(.*)') | |
14 | |
15 try: | |
16 os.makedirs(dest_dir) | |
17 except OSError, err: | |
18 if err.errno != errno.EEXIST: | |
19 raise | |
20 | |
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) | |
23 | |
24 for name in sys.argv[3:]: | |
25 if not name.endswith('.tex'): | |
26 continue | |
27 dest_name = os.path.join(dest_dir, name) | |
28 ifp = open(name) | |
29 ofp = open(dest_name, 'w') | |
30 new_par = True | |
31 line_num = 0 | |
32 for line in ifp: | |
33 line_num += 1 | |
34 if new_par: | |
35 m = line_re.match(line) | |
36 if m: | |
37 line = m.group(1) + feedback(name, line, line_num) + m.group(2) | |
38 new_par = False | |
39 elif not line.strip(): | |
40 new_par = True | |
41 ofp.write(line) |