]> git.ipfire.org Git - thirdparty/systemd.git/blame - make-man-index.py
journald: write tags also to user journal files
[thirdparty/systemd.git] / make-man-index.py
CommitLineData
9c4fa6ed
LP
1#!/usr/bin/env python
2
3from xml.etree.ElementTree import parse, Element, SubElement, tostring
88641113 4from sys import argv, stdout
9c4fa6ed
LP
5
6index = {}
7
7653b3c2
KS
8def prettify(elem, indent = 0):
9 s = "\n" + indent * " "
10 if len(elem):
11 if not elem.text or not elem.text.strip():
12 elem.text = s + " "
13 for e in elem:
14 prettify(e, indent + 1)
15 if not e.tail or not e.tail.strip():
16 e.tail = s + " "
17 if not e.tail or not e.tail.strip():
18 e.tail = s
19 else:
20 if indent and (not elem.tail or not elem.tail.strip()):
21 elem.tail = s
22
88641113 23for p in argv[1:]:
9c4fa6ed 24 t = parse(p)
88641113 25 section = t.find('./refmeta/manvolnum').text
7653b3c2 26 purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
9c4fa6ed 27 for f in t.findall('./refnamediv/refname'):
88641113 28 index[f.text] = (p, section, purpose)
9c4fa6ed
LP
29
30html = Element('html')
31
32head = SubElement(html, 'head')
33title = SubElement(head, 'title')
34title.text = 'Manual Page Index'
35
36body = SubElement(html, 'body')
37h1 = SubElement(body, 'h1')
38h1.text = 'Manual Page Index'
39
40letter = None
88641113
LP
41for n in sorted(index.keys(), key = str.lower):
42 path, section, purpose = index[n]
9c4fa6ed
LP
43
44 if path.endswith('.xml'):
45 path = path[:-4] + ".html"
46
47 c = path.rfind('/')
48 if c >= 0:
49 path = path[c+1:]
50
51 if letter is None or n[0].upper() != letter:
52 letter = n[0].upper()
53
a6c9b1c4 54 h2 = SubElement(body, 'h2')
9c4fa6ed
LP
55 h2.text = letter
56
57 ul = SubElement(body, 'ul')
58 ul.set('style', 'list-style-type:none')
59
92e1ecc6 60 li = SubElement(ul, 'li')
9c4fa6ed 61
92e1ecc6 62 a = SubElement(li, 'a')
9c4fa6ed
LP
63 a.set('href', path)
64 a.text = n + '(' + section + ')'
92e1ecc6
LP
65 a.tail = ' -- '
66
67 i = SubElement(li, 'i')
68 i.text = purpose
9c4fa6ed 69
051eaebb
LP
70hr = SubElement(body, 'hr')
71
72p = SubElement(body, 'p')
73p.text = "This index contains %s entries, referring to %i individual manual pages." % (len(index), len(argv)-1)
74
b56d18ee
MM
75if hasattr(stdout, "buffer"):
76 stdout = stdout.buffer
7653b3c2 77prettify(html)
88641113 78stdout.write(tostring(html))