]> git.ipfire.org Git - thirdparty/systemd.git/blob - make-man-index.py
nspawn: Fix minor typo in man page
[thirdparty/systemd.git] / make-man-index.py
1 #!/usr/bin/env python
2 # -*- Mode: python; indent-tabs-mode: nil -*- */
3 #
4 # This file is part of systemd.
5 #
6 # Copyright 2012 Lennart Poettering
7 #
8 # systemd is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation; either version 2.1 of the License, or
11 # (at your option) any later version.
12 #
13 # systemd is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
20
21 from xml.etree.ElementTree import parse, Element, SubElement, tostring
22 from sys import argv, stdout
23
24 index = {}
25
26 def prettify(elem, indent = 0):
27 s = "\n" + indent * " "
28 if len(elem):
29 if not elem.text or not elem.text.strip():
30 elem.text = s + " "
31 for e in elem:
32 prettify(e, indent + 1)
33 if not e.tail or not e.tail.strip():
34 e.tail = s + " "
35 if not e.tail or not e.tail.strip():
36 e.tail = s
37 else:
38 if indent and (not elem.tail or not elem.tail.strip()):
39 elem.tail = s
40
41 for p in argv[1:]:
42 t = parse(p)
43 section = t.find('./refmeta/manvolnum').text
44 purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
45 for f in t.findall('./refnamediv/refname'):
46 index[f.text] = (p, section, purpose)
47
48 html = Element('html')
49
50 head = SubElement(html, 'head')
51 title = SubElement(head, 'title')
52 title.text = 'Manual Page Index'
53
54 body = SubElement(html, 'body')
55 h1 = SubElement(body, 'h1')
56 h1.text = 'Manual Page Index'
57
58 letter = None
59 for n in sorted(index.keys(), key = str.lower):
60 path, section, purpose = index[n]
61
62 if path.endswith('.xml'):
63 path = path[:-4] + ".html"
64
65 c = path.rfind('/')
66 if c >= 0:
67 path = path[c+1:]
68
69 if letter is None or n[0].upper() != letter:
70 letter = n[0].upper()
71
72 h2 = SubElement(body, 'h2')
73 h2.text = letter
74
75 ul = SubElement(body, 'ul')
76 ul.set('style', 'list-style-type:none')
77
78 li = SubElement(ul, 'li')
79
80 a = SubElement(li, 'a')
81 a.set('href', path)
82 a.text = n + '(' + section + ')'
83 a.tail = ' -- '
84
85 i = SubElement(li, 'i')
86 i.text = purpose
87
88 hr = SubElement(body, 'hr')
89
90 p = SubElement(body, 'p')
91 p.text = "This index contains %s entries, referring to %i individual manual pages." % (len(index), len(argv)-1)
92
93 if hasattr(stdout, "buffer"):
94 stdout = stdout.buffer
95 prettify(html)
96 stdout.write(tostring(html))