comparison ja/fblinks @ 290:b0db5adf11c1 ja_root

fork Japanese translation.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Wed, 06 Feb 2008 17:43:11 +0900
parents en/fblinks@9457add294b8
children
comparison
equal deleted inserted replaced
289:7be02466421b 290:b0db5adf11c1
1 #!/usr/bin/python
2
3 import errno
4 import os
5 import re
6 import sys
7
8 hg_id = sys.argv[1]
9
10 dest_dir = sys.argv[2]
11
12 empty_re = re.compile(r'^\s*$')
13 line_re = re.compile(r'^(\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, ctx_id):
22 return r'\marginpar{\scriptsize \href{http://demesne:8000/book/feedback/submit/%s/%s/%d/}{Feedback}}' % (hg_id, name, ctx_id)
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
35
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)
60
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))