]> git.ipfire.org Git - thirdparty/systemd.git/blame - make-man-index.py
tmpfiles: exclude /tmp/systemd-private-* from cleanup
[thirdparty/systemd.git] / make-man-index.py
CommitLineData
f6b6728d 1# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
6b91ae13
LP
2#
3# This file is part of systemd.
4#
5# Copyright 2012 Lennart Poettering
f6b6728d 6# Copyright 2013 Zbigniew Jędrzejewski-Szmek
6b91ae13
LP
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/>.
9c4fa6ed 20
f6b6728d
ZJS
21import collections
22import xml.etree.ElementTree as tree
23import sys
dd6f5e4f 24MDASH = ' — ' if sys.version_info.major >= 3 else ' -- '
f6b6728d
ZJS
25
26TEMPLATE = '''\
27<refentry id="systemd.index">
28
29 <refentryinfo>
30 <title>systemd.index</title>
31 <productname>systemd</productname>
32
33 <authorgroup>
34 <author>
35 <contrib>Developer</contrib>
36 <firstname>Lennart</firstname>
37 <surname>Poettering</surname>
38 <email>lennart@poettering.net</email>
39 </author>
40 </authorgroup>
41 </refentryinfo>
42
43 <refmeta>
44 <refentrytitle>systemd.index</refentrytitle>
45 <manvolnum>7</manvolnum>
46 </refmeta>
47
48 <refnamediv>
49 <refname>systemd.index</refname>
50 <refpurpose>List all manpages from the systemd project</refpurpose>
51 </refnamediv>
52</refentry>
53'''
54
55SUMMARY = '''\
56 <refsect1>
57 <title>See Also</title>
58 <para>
59 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
60 </para>
61
62 <para id='counts' />
63 </refsect1>
64'''
65
66COUNTS = '\
67This index contains {count} entries, referring to {pages} individual manual pages.'
68
69def make_index(pages):
70 index = collections.defaultdict(list)
71 for p in pages:
72 t = tree.parse(p)
88641113 73 section = t.find('./refmeta/manvolnum').text
f6b6728d 74 refname = t.find('./refnamediv/refname').text
7653b3c2 75 purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
9c4fa6ed 76 for f in t.findall('./refnamediv/refname'):
f6b6728d
ZJS
77 infos = (f.text, section, purpose, refname)
78 index[f.text[0].upper()].append(infos)
79 return index
9c4fa6ed 80
f6b6728d
ZJS
81def add_letter(template, letter, pages):
82 refsect1 = tree.SubElement(template, 'refsect1')
83 title = tree.SubElement(refsect1, 'title')
84 title.text = letter
85 para = tree.SubElement(refsect1, 'para')
86 for info in sorted(pages, key=lambda info: str.lower(info[0])):
87 refname, section, purpose, realname = info
9c4fa6ed 88
f6b6728d
ZJS
89 b = tree.SubElement(para, 'citerefentry')
90 c = tree.SubElement(b, 'refentrytitle')
91 c.text = refname
92 d = tree.SubElement(b, 'manvolnum')
93 d.text = section
9c4fa6ed 94
dd6f5e4f 95 b.tail = MDASH + purpose # + ' (' + p + ')'
9c4fa6ed 96
f6b6728d 97 tree.SubElement(para, 'sbr')
9c4fa6ed 98
f6b6728d
ZJS
99def add_summary(template, indexpages):
100 count = 0
101 pages = set()
102 for group in indexpages:
103 count += len(group)
104 for info in group:
105 refname, section, purpose, realname = info
106 pages.add((realname, section))
9c4fa6ed 107
f6b6728d
ZJS
108 refsect1 = tree.fromstring(SUMMARY)
109 template.append(refsect1)
9c4fa6ed 110
f6b6728d
ZJS
111 para = template.find(".//para[@id='counts']")
112 para.text = COUNTS.format(count=count, pages=len(pages))
9c4fa6ed 113
f6b6728d
ZJS
114def make_page(xml_files):
115 template = tree.fromstring(TEMPLATE)
116 index = make_index(xml_files)
9c4fa6ed 117
f6b6728d
ZJS
118 for letter in sorted(index):
119 add_letter(template, letter, index[letter])
9c4fa6ed 120
f6b6728d 121 add_summary(template, index.values())
9c4fa6ed 122
f6b6728d 123 return template
92e1ecc6 124
f6b6728d
ZJS
125if __name__ == '__main__':
126 tree.dump(make_page(sys.argv[1:]))