hgbook
diff fr/fblinks @ 1020:53dfddc566d8
French: corrections in xml tags
author | André Sintzoff <andre.sintzoff@gmail.com> |
---|---|
date | Tue Dec 01 13:40:01 2009 +0100 (2009-12-01) |
parents | 9457add294b8 |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/fr/fblinks Tue Dec 01 13:40:01 2009 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +#!/usr/bin/python 1.5 + 1.6 +import errno 1.7 +import os 1.8 +import re 1.9 +import sys 1.10 + 1.11 +hg_id = sys.argv[1] 1.12 + 1.13 +dest_dir = sys.argv[2] 1.14 + 1.15 +empty_re = re.compile(r'^\s*$') 1.16 +line_re = re.compile(r'^(\w+)(.*)') 1.17 + 1.18 +try: 1.19 + os.makedirs(dest_dir) 1.20 +except OSError, err: 1.21 + if err.errno != errno.EEXIST: 1.22 + raise 1.23 + 1.24 +def feedback(name, text, ctx_id): 1.25 + return r'\marginpar{\scriptsize \href{http://demesne:8000/book/feedback/submit/%s/%s/%d/}{Feedback}}' % (hg_id, name, ctx_id) 1.26 + 1.27 +ctxs = {} 1.28 +try: 1.29 + cfp = open(os.path.join(dest_dir, 'rev-' + hg_id + '.ctx'), 'r+') 1.30 + for line in cfp: 1.31 + f, l, c = line.split(':', 2) 1.32 + ctxs[(f, int(l))] = c.strip() 1.33 +except IOError, err: 1.34 + if err.errno != errno.ENOENT: raise 1.35 + cfp = open(os.path.join(dest_dir, 'rev-' + hg_id + '.ctx'), 'w+') 1.36 + 1.37 +changes = 0 1.38 + 1.39 +for name in sys.argv[3:]: 1.40 + if not name.endswith('.tex'): 1.41 + continue 1.42 + dest_name = os.path.join(dest_dir, name) 1.43 + ifp = open(name) 1.44 + ofp = open(dest_name, 'w') 1.45 + new_par = True 1.46 + line_num = 0 1.47 + par_num = 0 1.48 + for line in ifp: 1.49 + line_num += 1 1.50 + if new_par: 1.51 + m = line_re.match(line) 1.52 + if m: 1.53 + par_num += 1 1.54 + ls = line.strip() 1.55 + if ctxs.get((name, par_num)) != ls: 1.56 + ctxs[(name, par_num)] = ls 1.57 + changes += 1 1.58 + line = m.group(1) + feedback(name, line, par_num) + m.group(2) 1.59 + new_par = False 1.60 + elif not line.strip(): 1.61 + new_par = True 1.62 + ofp.write(line) 1.63 + 1.64 +if changes: 1.65 + cfp.seek(0) 1.66 + print '%s: %d changes' % (cfp.name, changes) 1.67 + ctxs = ctxs.items() 1.68 + ctxs.sort() 1.69 + for ((file, line), content) in ctxs: 1.70 + cfp.write('%s:%d: %s\n' % (file, line, content))