]>
Commit | Line | Data |
---|---|---|
9c4fa6ed LP |
1 | #!/usr/bin/env python |
2 | ||
3 | from xml.etree.ElementTree import parse, Element, SubElement, tostring | |
88641113 | 4 | from sys import argv, stdout |
9c4fa6ed LP |
5 | |
6 | index = {} | |
7 | ||
88641113 | 8 | for p in argv[1:]: |
9c4fa6ed | 9 | t = parse(p) |
88641113 LP |
10 | section = t.find('./refmeta/manvolnum').text |
11 | purpose = t.find('./refnamediv/refpurpose').text | |
9c4fa6ed | 12 | for f in t.findall('./refnamediv/refname'): |
88641113 | 13 | index[f.text] = (p, section, purpose) |
9c4fa6ed LP |
14 | |
15 | html = Element('html') | |
16 | ||
17 | head = SubElement(html, 'head') | |
18 | title = SubElement(head, 'title') | |
19 | title.text = 'Manual Page Index' | |
20 | ||
21 | body = SubElement(html, 'body') | |
22 | h1 = SubElement(body, 'h1') | |
23 | h1.text = 'Manual Page Index' | |
24 | ||
25 | letter = None | |
88641113 LP |
26 | for n in sorted(index.keys(), key = str.lower): |
27 | path, section, purpose = index[n] | |
9c4fa6ed LP |
28 | |
29 | if path.endswith('.xml'): | |
30 | path = path[:-4] + ".html" | |
31 | ||
32 | c = path.rfind('/') | |
33 | if c >= 0: | |
34 | path = path[c+1:] | |
35 | ||
36 | if letter is None or n[0].upper() != letter: | |
37 | letter = n[0].upper() | |
38 | ||
a6c9b1c4 | 39 | h2 = SubElement(body, 'h2') |
9c4fa6ed LP |
40 | h2.text = letter |
41 | ||
42 | ul = SubElement(body, 'ul') | |
43 | ul.set('style', 'list-style-type:none') | |
44 | ||
92e1ecc6 | 45 | li = SubElement(ul, 'li') |
9c4fa6ed | 46 | |
92e1ecc6 | 47 | a = SubElement(li, 'a') |
9c4fa6ed LP |
48 | a.set('href', path) |
49 | a.text = n + '(' + section + ')' | |
92e1ecc6 LP |
50 | a.tail = ' -- ' |
51 | ||
52 | i = SubElement(li, 'i') | |
53 | i.text = purpose | |
9c4fa6ed | 54 | |
051eaebb LP |
55 | hr = SubElement(body, 'hr') |
56 | ||
57 | p = SubElement(body, 'p') | |
58 | p.text = "This index contains %s entries, referring to %i individual manual pages." % (len(index), len(argv)-1) | |
59 | ||
88641113 | 60 | stdout.write(tostring(html)) |