bos@599: #!/usr/bin/env python
bos@599:
bos@599: import glob, os, re
bos@599:
bos@599: chapter_re = re.compile(r'<(chapter|appendix|preface)\s+id="([^"]+)">')
bos@599: filename_re = re.compile(r'<\?dbhtml filename="([^"]+)"\?>')
bos@599: title_re = re.compile(r'
(.*)')
bos@599:
bos@687: chapters = (sorted(glob.glob('../en/ch*.xml')) +
bos@687: sorted(glob.glob('../en/app*.xml')))
bos@599:
bos@599: fp = open('index-read.html.in', 'w')
bos@599:
bos@599: print >> fp, '''
bos@599: {% extends "boilerplate.html" %}
bos@599: {% block bodycontent %}
bos@599:
bos@599: '''
bos@599:
bos@599: ch = 0
bos@599: app = 0
bos@599: ab = 0
bos@599: for c in chapters:
bos@599: filename = None
bos@599: title = None
bos@599: chapid = None
bos@599: chaptype = None
bos@599: for line in open(c):
bos@599: m = chapter_re.search(line)
bos@599: if m:
bos@599: chaptype, chapid = m.groups()
bos@599: m = filename_re.search(line)
bos@599: if m:
bos@599: filename = m.group(1)
bos@599: m = title_re.search(line)
bos@599: if m:
bos@599: title = m.group(1)
bos@599: if filename and title and chapid:
bos@599: if chaptype == 'appendix':
bos@599: num = chr(ord('A') + app)
bos@599: app += 1
bos@599: else:
bos@599: num = ch
bos@599: ch += 1
bos@599: ab += 1
bos@599: date = os.popen('hg log -l1 --template "{date|isodate}" ' + c).read().split(None, 1)[0]
bos@599: args = {
bos@599: 'ab': "ab"[ab % 2],
bos@599: 'date': date,
bos@599: 'chapid': chapid,
bos@599: 'num': num,
bos@599: 'filename': filename,
bos@599: 'title': title,
bos@599: }
bos@599: print >> fp, '- %(date)s
%(num)s. %(title)s ' % args
bos@599: break
bos@599:
bos@599: print >> fp, '''
bos@599: {% endblock %}'''
bos@599:
bos@599: fp.close()