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