]> git.ipfire.org Git - thirdparty/systemd.git/blob - make-man-index.py
min: generate an index page for all man pages
[thirdparty/systemd.git] / make-man-index.py
1 #!/usr/bin/env python
2
3 from xml.etree.ElementTree import parse, Element, SubElement, tostring
4 import sys
5
6 index = {}
7
8 for p in sys.argv[1:]:
9 t = parse(p)
10 section = t.find('./refmeta/manvolnum').text;
11 for f in t.findall('./refnamediv/refname'):
12 index[f.text] = (p, section)
13
14 k = index.keys()
15 k.sort(key = str.lower)
16
17
18 html = Element('html')
19
20 head = SubElement(html, 'head')
21 title = SubElement(head, 'title')
22 title.text = 'Manual Page Index'
23
24 body = SubElement(html, 'body')
25 h1 = SubElement(body, 'h1')
26 h1.text = 'Manual Page Index'
27
28 letter = None
29
30 for n in k:
31 path, section = index[n]
32
33 if path.endswith('.xml'):
34 path = path[:-4] + ".html"
35
36 c = path.rfind('/')
37 if c >= 0:
38 path = path[c+1:]
39
40 if letter is None or n[0].upper() != letter:
41 letter = n[0].upper()
42
43 h2 = SubElement(body, 'h1')
44 h2.text = letter
45
46 ul = SubElement(body, 'ul')
47 ul.set('style', 'list-style-type:none')
48
49 li = SubElement(ul, 'li');
50
51 a = SubElement(li, 'a');
52 a.set('href', path)
53 a.text = n + '(' + section + ')'
54
55 print tostring(html)