]> git.ipfire.org Git - thirdparty/systemd.git/blame - make-directive-index.py
man: docbook consitency fixes
[thirdparty/systemd.git] / make-directive-index.py
CommitLineData
e7098b69
ZJS
1# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
2#
3# This file is part of systemd.
4#
5# Copyright 2012 Zbigniew Jędrzejewski-Szmek
6#
7# systemd is free software; you can redistribute it and/or modify it
8# under the terms of the GNU Lesser General Public License as published by
9# the Free Software Foundation; either version 2.1 of the License, or
10# (at your option) any later version.
11#
12# systemd is distributed in the hope that it will be useful, but
13# WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15# Lesser General Public License for more details.
16#
17# You should have received a copy of the GNU Lesser General Public License
18# along with systemd; If not, see <http://www.gnu.org/licenses/>.
19
d9cfd694
ZJS
20import sys
21import collections
22import xml.etree.ElementTree as tree
23
24TEMPLATE = '''\
25<refentry id="systemd.directives">
26
27 <refentryinfo>
28 <title>systemd.directives</title>
29 <productname>systemd</productname>
30
31 <authorgroup>
32 <author>
33 <contrib>Developer</contrib>
34 <firstname>Zbigniew</firstname>
35 <surname>Jędrzejewski-Szmek</surname>
36 <email>zbyszek@in.waw.pl</email>
37 </author>
38 </authorgroup>
39 </refentryinfo>
40
41 <refmeta>
42 <refentrytitle>systemd.directives</refentrytitle>
9cc2c8b7 43 <manvolnum>7</manvolnum>
d9cfd694
ZJS
44 </refmeta>
45
46 <refnamediv>
47 <refname>systemd.directives</refname>
48 <refpurpose>Index of configuration directives</refpurpose>
49 </refnamediv>
50
51 <refsect1>
52 <title>Unit directives</title>
53
54 <para>Directives for configuring units, used in unit
55 files.</para>
56
57 <variablelist id='unit-directives' />
58 </refsect1>
e1abd3ef 59
ffafe91b
ZJS
60 <refsect1>
61 <title>System manager directives</title>
62
63 <para>Directives for configuring the behaviour of the
64 systemd process.</para>
65
66 <variablelist id='systemd-directives' />
67 </refsect1>
68
08177c85
ZJS
69 <refsect1>
70 <title>Options on the kernel command line</title>
71
72 <para>Kernel boot options for configuring the behaviour of the
73 systemd process.</para>
74
75 <variablelist id='kernel-commandline-directives' />
76 </refsect1>
77
78 <refsect1>
79 <title>Environment variables</title>
80
81 <para>Environment variables understood by the systemd process.</para>
82
83 <variablelist id='environment-variables' />
84 </refsect1>
85
e1abd3ef
ZJS
86 <refsect1>
87 <title>UDEV directives</title>
88
89 <para>Directives for configuring systemd units through the
90 udev database.</para>
91
92 <variablelist id='udev-directives' />
93 </refsect1>
f6c2e28b
ZJS
94
95 <refsect1>
96 <title>Journal directives</title>
97
98 <para>Directives for configuring the behaviour of the
99 journald process.</para>
100
101 <variablelist id='journal-directives' />
102 </refsect1>
4a431c9a
ZJS
103
104 <refsect1>
105 <title>bootchart.conf directives</title>
106
107 <para>Directives for configuring the behaviour of the
108 systemd-bootchart process.</para>
109
110 <variablelist id='bootchart-directives' />
111 </refsect1>
0acfdd61
ZJS
112
113 <refsect1>
114 <title>Colophon</title>
115 <para id='colophon' />
116 </refsect1>
d9cfd694
ZJS
117</refentry>
118'''
119
0acfdd61
ZJS
120COLOPHON = '''\
121This index contains {count} entries in {sections} sections,
122referring to {pages} individual manual pages.
123'''
124
d9cfd694
ZJS
125def _extract_directives(directive_groups, page):
126 t = tree.parse(page)
127 section = t.find('./refmeta/manvolnum').text
128 pagename = t.find('./refmeta/refentrytitle').text
129 for variablelist in t.iterfind('.//variablelist'):
130 klass = variablelist.attrib.get('class') or 'unit-directives'
131 stor = directive_groups[klass]
132 for varname in variablelist.iterfind('./varlistentry/term/varname'):
133 text = ''.join(varname.text.partition('=')[:2])
134 stor[text].append((pagename, section))
135
eeb019b5
ZJS
136def _make_section(template, name, directives):
137 varlist = template.find(".//*[@id='{}']".format(name))
d9cfd694
ZJS
138 for varname, manpages in sorted(directives.items()):
139 entry = tree.SubElement(varlist, 'varlistentry')
140 a = tree.SubElement(tree.SubElement(entry, 'term'), 'varname')
141 a.text = varname
142 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
143
144 b = None
145 for manpage, manvolume in sorted(manpages):
146 if b is not None:
147 b.tail = ', '
148 b = tree.SubElement(para, 'citerefentry')
149 c = tree.SubElement(b, 'refentrytitle')
150 c.text = manpage
151 d = tree.SubElement(b, 'manvolnum')
152 d.text = manvolume
153 entry.tail = '\n\n'
154
0acfdd61
ZJS
155def _make_colophon(template, groups):
156 count = 0
157 pages = set()
158 for group in groups:
159 count += len(group)
160 for pagelist in group.values():
161 pages |= set(pagelist)
162
163 para = template.find(".//para[@id='colophon']")
164 para.text = COLOPHON.format(count=count,
165 sections=len(groups),
166 pages=len(pages))
167
eeb019b5 168def _make_page(template, directive_groups):
d9cfd694
ZJS
169 """Create an XML tree from directive_groups.
170
171 directive_groups = {
172 'class': {'variable': [('manpage', 'manvolume'), ...],
173 'variable2': ...},
174 ...
175 }
176 """
d9cfd694 177 for name, directives in directive_groups.items():
eeb019b5 178 _make_section(template, name, directives)
d9cfd694 179
0acfdd61
ZJS
180 _make_colophon(template, directive_groups.values())
181
eeb019b5 182 return template
d9cfd694
ZJS
183
184def make_page(xml_files):
185 "Extract directives from xml_files and return XML index tree."
eeb019b5
ZJS
186 template = tree.fromstring(TEMPLATE)
187 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
d9cfd694 188 directive_groups = {name:collections.defaultdict(list)
eeb019b5 189 for name in names}
d9cfd694
ZJS
190 for page in xml_files:
191 _extract_directives(directive_groups, page)
192
eeb019b5 193 return _make_page(template, directive_groups)
d9cfd694
ZJS
194
195if __name__ == '__main__':
196 tree.dump(make_page(sys.argv[1:]))