aboutsummaryrefslogtreecommitdiffstats
path: root/admin/bin/mm2do
blob: 661a25f4b8f953c7ec0c90a19d3e28c733cd8b13 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /usr/bin/env python
#
# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

"""Generate the todo.ht file from the plain-text TODO file."""

import sys

infp = open(sys.argv[1])
outfp = open(sys.argv[2], 'w')

SPACE = ' '

print >> outfp, 'Title: The Mailman Wishlist\n'

def dumpsection(header, items, hasitems):
    # We're looking at a header
    if header:
        # output the previous section
        print >> outfp, '<h3>', header, '</h3>'
    if hasitems:
        print >> outfp, '<ul>'
        for item in items:
            if item:
                print >> outfp, '    <li>', SPACE.join(item)
        print >> outfp, '</ul>'
    else:
        for item in items:
            print >> outfp, SPACE.join(item), '<p>'



header = ''
items = [['']]
hasitems = False
inpreamble = True
while True:
    line = infp.readline()
    if not line or line[0] == '\f':
        break
    # Skip the legalese preamble
    if inpreamble:
        if line.strip():
            continue
        else:
            inpreamble = False
    if not line[0].isspace():
        dumpsection(header, items, hasitems)
        header = line
        items = [[]]
        continue
    # find out what the first non-ws character on the line is
    line = line.lstrip()
    if line and line[0] == '-':
        items.append([line[2:-1]])
        hasitems = True
    else:
        if not line:
            continue
        items[-1].append(line)

dumpsection(header, items, hasitems)