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