annotate web/genindex.py @ 838:d1f676a6a4b3 default tip

update mq chapter. propagate ef53d025f410.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 03 Dec 2009 01:26:08 +0900
parents 0ffae4ee4c47
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
698
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
1 #!/usr/bin/env python
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
2
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
3 import glob, os, re
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
4
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
5 chapter_re = re.compile(r'<(chapter|appendix|preface)\s+id="([^"]+)">')
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
6 filename_re = re.compile(r'<\?dbhtml filename="([^"]+)"\?>')
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
7 title_re = re.compile(r'<title>(.*)</title>')
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
8
815
0ffae4ee4c47 Fix indexing.
Bryan O'Sullivan <bos@serpentine.com>
parents: 698
diff changeset
9 chapters = (sorted(glob.glob('../en/ch*.xml')) +
0ffae4ee4c47 Fix indexing.
Bryan O'Sullivan <bos@serpentine.com>
parents: 698
diff changeset
10 sorted(glob.glob('../en/app*.xml')))
698
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
11
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
12 fp = open('index-read.html.in', 'w')
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
13
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
14 print >> fp, '''<!-- -*- html -*- -->
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
15 {% extends "boilerplate.html" %}
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
16 {% block bodycontent %}
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
17 <div class="navheader"><h1 class="booktitle">Mercurial: The Definitive Guide<div class="authors">by Bryan O'Sullivan</div></h1></div>
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
18 <div class="book"><ul class="booktoc">'''
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
19
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
20 ch = 0
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
21 app = 0
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
22 ab = 0
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
23 for c in chapters:
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
24 filename = None
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
25 title = None
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
26 chapid = None
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
27 chaptype = None
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
28 for line in open(c):
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
29 m = chapter_re.search(line)
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
30 if m:
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
31 chaptype, chapid = m.groups()
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
32 m = filename_re.search(line)
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
33 if m:
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
34 filename = m.group(1)
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
35 m = title_re.search(line)
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
36 if m:
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
37 title = m.group(1)
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
38 if filename and title and chapid:
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
39 if chaptype == 'appendix':
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
40 num = chr(ord('A') + app)
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
41 app += 1
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
42 else:
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
43 num = ch
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
44 ch += 1
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
45 ab += 1
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
46 date = os.popen('hg log -l1 --template "{date|isodate}" ' + c).read().split(None, 1)[0]
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
47 args = {
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
48 'ab': "ab"[ab % 2],
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
49 'date': date,
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
50 'chapid': chapid,
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
51 'num': num,
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
52 'filename': filename,
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
53 'title': title,
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
54 }
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
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
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
56 break
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
57
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
58 print >> fp, '''</ul></div>
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
59 {% endblock %}'''
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
60
9e8e5292acaa Generate a nice readable index.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
61 fp.close()