annotate en/fblinks @ 536:05bfbe50e7e4

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