hgbook
diff it/web/genindex.py @ 976:713f0f69029a
merge with Italian, and very (few) work on ch03
author | Romain PELISSE <belaran@gmail.com> |
---|---|
date | Fri Sep 04 16:33:35 2009 +0200 (2009-09-04) |
parents | |
children | 719b03ea27c8 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/it/web/genindex.py Fri Sep 04 16:33:35 2009 +0200 1.3 @@ -0,0 +1,63 @@ 1.4 +# This script works with Python 3.0 or above 1.5 + 1.6 +import glob, os, re 1.7 + 1.8 +chapter_re = re.compile(r'<(chapter|appendix|preface|bibliography)\s+id="([^"]+)">') 1.9 +filename_re = re.compile(r'<\?dbhtml filename="([^"]+)"\?>') 1.10 +title_re = re.compile(r'<title>(.*)</title>') 1.11 + 1.12 +chapters = (sorted(glob.glob('../ch*.xml')) + 1.13 + sorted(glob.glob('../app*.xml')) + 1.14 + sorted(glob.glob('../biblio*.xml'))) 1.15 + 1.16 +fp = open('index-read.html.in', 'w', encoding='utf-8') 1.17 + 1.18 +print(''' 1.19 +<div class="navheader"><h1 class="booktitle">Mercurial: la guida definitiva<div class="authors">di Bryan O\’Sullivan</div></h1></div> 1.20 +<div class="book"><ul class="booktoc">''', file=fp) 1.21 + 1.22 +ch = 0 1.23 +app = 0 1.24 +ab = 0 1.25 +for c in chapters: 1.26 + filename = None 1.27 + title = None 1.28 + chapid = None 1.29 + chaptype = None 1.30 + for line in open(c, encoding='utf-8'): 1.31 + m = chapter_re.search(line) 1.32 + if m: 1.33 + chaptype, chapid = m.groups() 1.34 + m = filename_re.search(line) 1.35 + if m: 1.36 + filename = m.group(1) 1.37 + m = title_re.search(line) 1.38 + if m: 1.39 + title = m.group(1) 1.40 + if filename and title and chapid: 1.41 + if chaptype == 'bibliography': 1.42 + num = '' 1.43 + elif chaptype == 'appendix': 1.44 + num = str(chr(ord('A') + app)) + '. ' 1.45 + app += 1 1.46 + else: 1.47 + num = str(ch) + '. ' 1.48 + ch += 1 1.49 + if '&' in title: 1.50 + title = title.replace('&', '\&') 1.51 + ab += 1 1.52 + date = os.popen('hg log -l1 --template "{date|isodate}" ' + c).read().split(None, 1)[0] 1.53 + args = { 1.54 + 'ab': "ab"[ab % 2], 1.55 + 'date': date, 1.56 + # 'chapid': chapid, 1.57 + 'num': num, 1.58 + 'filename': filename, 1.59 + 'title': title, 1.60 + } 1.61 + print('<li class="zebra_%(ab)s"><span class="chapinfo">%(date)s</span>%(num)s<a href="%(filename)s">%(title)s</a></li>' % args, file=fp) 1.62 + break 1.63 + 1.64 +print('</ul></div>', file=fp) 1.65 + 1.66 +fp.close()