hgbook

annotate web/genindex.py @ 676:29f0f79cf614

Update paragraph IDs
author Bryan O'Sullivan <bos@serpentine.com>
date Thu Apr 16 23:46:45 2009 -0700 (2009-04-16)
parents
children 0ffae4ee4c47
rev   line source
bos@599 1 #!/usr/bin/env python
bos@599 2
bos@599 3 import glob, os, re
bos@599 4
bos@599 5 chapter_re = re.compile(r'<(chapter|appendix|preface)\s+id="([^"]+)">')
bos@599 6 filename_re = re.compile(r'<\?dbhtml filename="([^"]+)"\?>')
bos@599 7 title_re = re.compile(r'<title>(.*)</title>')
bos@599 8
bos@599 9 chapters = glob.glob('../en/ch*.xml') + glob.glob('../en/app*.xml')
bos@599 10
bos@599 11 fp = open('index-read.html.in', 'w')
bos@599 12
bos@599 13 print >> fp, '''<!-- -*- html -*- -->
bos@599 14 {% extends "boilerplate.html" %}
bos@599 15 {% block bodycontent %}
bos@599 16 <div class="navheader"><h1 class="booktitle">Mercurial: The Definitive Guide<div class="authors">by Bryan O'Sullivan</div></h1></div>
bos@599 17 <div class="book"><ul class="booktoc">'''
bos@599 18
bos@599 19 ch = 0
bos@599 20 app = 0
bos@599 21 ab = 0
bos@599 22 for c in chapters:
bos@599 23 filename = None
bos@599 24 title = None
bos@599 25 chapid = None
bos@599 26 chaptype = None
bos@599 27 for line in open(c):
bos@599 28 m = chapter_re.search(line)
bos@599 29 if m:
bos@599 30 chaptype, chapid = m.groups()
bos@599 31 m = filename_re.search(line)
bos@599 32 if m:
bos@599 33 filename = m.group(1)
bos@599 34 m = title_re.search(line)
bos@599 35 if m:
bos@599 36 title = m.group(1)
bos@599 37 if filename and title and chapid:
bos@599 38 if chaptype == 'appendix':
bos@599 39 num = chr(ord('A') + app)
bos@599 40 app += 1
bos@599 41 else:
bos@599 42 num = ch
bos@599 43 ch += 1
bos@599 44 ab += 1
bos@599 45 date = os.popen('hg log -l1 --template "{date|isodate}" ' + c).read().split(None, 1)[0]
bos@599 46 args = {
bos@599 47 'ab': "ab"[ab % 2],
bos@599 48 'date': date,
bos@599 49 'chapid': chapid,
bos@599 50 'num': num,
bos@599 51 'filename': filename,
bos@599 52 'title': title,
bos@599 53 }
bos@599 54 print >> fp, '<li class="zebra_%(ab)s"><span class="chapinfo">%(date)s<a href="/feeds/comments/%(chapid)s/"><img src="/support/figs/rss.png"/></a></span>%(num)s. <a href="%(filename)s">%(title)s</a></li>' % args
bos@599 55 break
bos@599 56
bos@599 57 print >> fp, '''</ul></div>
bos@599 58 {% endblock %}'''
bos@599 59
bos@599 60 fp.close()