]> git.ipfire.org Git - thirdparty/systemd.git/blob - make-man-index.py
man: show man page summary in index, too
[thirdparty/systemd.git] / make-man-index.py
1 #!/usr/bin/env python
2
3 from xml.etree.ElementTree import parse, Element, SubElement, tostring
4 from sys import argv, stdout
5
6 index = {}
7
8 for p in argv[1:]:
9 t = parse(p)
10 section = t.find('./refmeta/manvolnum').text
11 purpose = t.find('./refnamediv/refpurpose').text
12 for f in t.findall('./refnamediv/refname'):
13 index[f.text] = (p, section, purpose)
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
26 for n in sorted(index.keys(), key = str.lower):
27 path, section, purpose = index[n]
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
39 h2 = SubElement(body, 'h1')
40 h2.text = letter
41
42 ul = SubElement(body, 'ul')
43 ul.set('style', 'list-style-type:none')
44
45 li = SubElement(ul, 'li');
46
47 a = SubElement(li, 'a');
48 a.set('href', path)
49 a.text = n + '(' + section + ')'
50 a.tail = ' -- ' + purpose
51
52 stdout.write(tostring(html))