]> git.ipfire.org Git - thirdparty/systemd.git/blame - make-directive-index.py
Use assert_return in more of the public API
[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#
ccc9a4f9 5# Copyright 2012-2013 Zbigniew Jędrzejewski-Szmek
e7098b69
ZJS
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
ccc9a4f9 22import re
1a13e31d 23from xml_helper import *
827f70eb 24from copy import deepcopy
d9cfd694
ZJS
25
26TEMPLATE = '''\
56ba3c78 27<refentry id="systemd.directives" conditional="HAVE_PYTHON">
d9cfd694
ZJS
28
29 <refentryinfo>
30 <title>systemd.directives</title>
31 <productname>systemd</productname>
32
33 <authorgroup>
34 <author>
35 <contrib>Developer</contrib>
36 <firstname>Zbigniew</firstname>
37 <surname>Jędrzejewski-Szmek</surname>
38 <email>zbyszek@in.waw.pl</email>
39 </author>
40 </authorgroup>
41 </refentryinfo>
42
43 <refmeta>
44 <refentrytitle>systemd.directives</refentrytitle>
9cc2c8b7 45 <manvolnum>7</manvolnum>
d9cfd694
ZJS
46 </refmeta>
47
48 <refnamediv>
49 <refname>systemd.directives</refname>
50 <refpurpose>Index of configuration directives</refpurpose>
51 </refnamediv>
52
53 <refsect1>
54 <title>Unit directives</title>
55
56 <para>Directives for configuring units, used in unit
57 files.</para>
58
59 <variablelist id='unit-directives' />
60 </refsect1>
e1abd3ef 61
08177c85
ZJS
62 <refsect1>
63 <title>Options on the kernel command line</title>
64
65 <para>Kernel boot options for configuring the behaviour of the
66 systemd process.</para>
67
ccc9a4f9 68 <variablelist id='kernel-commandline-options' />
08177c85
ZJS
69 </refsect1>
70
71 <refsect1>
72 <title>Environment variables</title>
73
ccc9a4f9
ZJS
74 <para>Environment variables understood by the systemd
75 manager and other programs.</para>
08177c85
ZJS
76
77 <variablelist id='environment-variables' />
78 </refsect1>
79
e1abd3ef
ZJS
80 <refsect1>
81 <title>UDEV directives</title>
82
83 <para>Directives for configuring systemd units through the
84 udev database.</para>
85
86 <variablelist id='udev-directives' />
87 </refsect1>
f6c2e28b 88
1f06807c
TG
89 <refsect1>
90 <title>Network directives</title>
91
92 <para>Directives for configuring network links through the
46b0925d
TG
93 net-setup-link udev builtin and networks through
94 systemd-networkd.</para>
1f06807c
TG
95
96 <variablelist id='network-directives' />
97 </refsect1>
98
f6c2e28b 99 <refsect1>
ccc9a4f9 100 <title>Journal fields</title>
f6c2e28b 101
ccc9a4f9 102 <para>Fields in the journal events with a well known meaning.</para>
f6c2e28b
ZJS
103
104 <variablelist id='journal-directives' />
105 </refsect1>
4a431c9a 106
ccc9a4f9
ZJS
107 <refsect1>
108 <title>PAM configuration directives</title>
109
110 <para>Directives for configuring PAM behaviour.</para>
111
112 <variablelist id='pam-directives' />
113 </refsect1>
114
115 <refsect1>
116 <title>crypttab options</title>
117
118 <para>Options which influence mounted filesystems and
119 encrypted volumes.</para>
120
121 <variablelist id='crypttab-options' />
122 </refsect1>
123
124 <refsect1>
125 <title>System manager directives</title>
126
127 <para>Directives for configuring the behaviour of the
128 systemd process.</para>
129
130 <variablelist id='systemd-directives' />
131 </refsect1>
132
4a431c9a
ZJS
133 <refsect1>
134 <title>bootchart.conf directives</title>
135
136 <para>Directives for configuring the behaviour of the
137 systemd-bootchart process.</para>
138
139 <variablelist id='bootchart-directives' />
140 </refsect1>
0acfdd61 141
ccc9a4f9
ZJS
142 <refsect1>
143 <title>command-line options</title>
144
145 <para>Command-line options accepted by programs in the
146 systemd suite.</para>
147
148 <variablelist id='options' />
149 </refsect1>
150
785a51eb
ZJS
151 <refsect1>
152 <title>Constants</title>
153
154 <para>Various constant used and/or defined by systemd.</para>
155
156 <variablelist id='constants' />
157 </refsect1>
158
ccc9a4f9
ZJS
159 <refsect1>
160 <title>Miscellaneous options and directives</title>
161
162 <para>Other configuration elements which don't fit in
163 any of the above groups.</para>
164
165 <variablelist id='miscellaneous' />
166 </refsect1>
167
a4e0b94d
ZJS
168 <refsect1>
169 <title>Files and directories</title>
170
171 <para>Paths and file names referred to in the
172 documentation.</para>
173
174 <variablelist id='filenames' />
175 </refsect1>
176
0acfdd61
ZJS
177 <refsect1>
178 <title>Colophon</title>
179 <para id='colophon' />
180 </refsect1>
d9cfd694
ZJS
181</refentry>
182'''
183
0acfdd61
ZJS
184COLOPHON = '''\
185This index contains {count} entries in {sections} sections,
186referring to {pages} individual manual pages.
187'''
188
d970bd6d 189def _extract_directives(directive_groups, formatting, page):
1a13e31d 190 t = xml_parse(page)
d9cfd694
ZJS
191 section = t.find('./refmeta/manvolnum').text
192 pagename = t.find('./refmeta/refentrytitle').text
a4e0b94d
ZJS
193
194 storopt = directive_groups['options']
d9cfd694 195 for variablelist in t.iterfind('.//variablelist'):
ccc9a4f9
ZJS
196 klass = variablelist.attrib.get('class')
197 storvar = directive_groups[klass or 'miscellaneous']
ccc9a4f9
ZJS
198 # <option>s go in OPTIONS, unless class is specified
199 for xpath, stor in (('./varlistentry/term/varname', storvar),
200 ('./varlistentry/term/option',
201 storvar if klass else storopt)):
202 for name in variablelist.iterfind(xpath):
203 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
204 stor[text].append((pagename, section))
d970bd6d
ZJS
205 if text not in formatting:
206 # use element as formatted display
699ad6c0
ZJS
207 if name.text[-1] in '= ':
208 name.clear()
209 else:
210 name.tail = ''
d970bd6d
ZJS
211 name.text = text
212 formatting[text] = name
d9cfd694 213
a4e0b94d 214 storfile = directive_groups['filenames']
845c5324
ZJS
215 for xpath, absolute_only in (('.//refsynopsisdiv//filename', False),
216 ('.//refsynopsisdiv//command', False),
217 ('.//filename', True)):
a4e0b94d 218 for name in t.iterfind(xpath):
845c5324
ZJS
219 if absolute_only and not (name.text and name.text.startswith('/')):
220 continue
221 if name.attrib.get('noindex'):
222 continue
a4e0b94d
ZJS
223 name.tail = ''
224 if name.text:
845c5324
ZJS
225 if name.text.endswith('*'):
226 name.text = name.text[:-1]
a4e0b94d
ZJS
227 if not name.text.startswith('.'):
228 text = name.text.partition(' ')[0]
229 if text != name.text:
230 name.clear()
231 name.text = text
845c5324
ZJS
232 if text.endswith('/'):
233 text = text[:-1]
a4e0b94d
ZJS
234 storfile[text].append((pagename, section))
235 if text not in formatting:
236 # use element as formatted display
237 formatting[text] = name
238 else:
239 text = ' '.join(name.itertext())
240 storfile[text].append((pagename, section))
241 formatting[text] = name
242
785a51eb
ZJS
243 storfile = directive_groups['constants']
244 for name in t.iterfind('.//constant'):
245 if name.attrib.get('noindex'):
246 continue
247 name.tail = ''
248 if name.text.startswith('('): # a cast, strip it
249 name.text = name.text.partition(' ')[2]
250 storfile[name.text].append((pagename, section))
251 formatting[name.text] = name
252
d970bd6d 253def _make_section(template, name, directives, formatting):
eeb019b5 254 varlist = template.find(".//*[@id='{}']".format(name))
d9cfd694
ZJS
255 for varname, manpages in sorted(directives.items()):
256 entry = tree.SubElement(varlist, 'varlistentry')
d970bd6d 257 term = tree.SubElement(entry, 'term')
827f70eb
ZJS
258 display = deepcopy(formatting[varname])
259 term.append(display)
d970bd6d 260
d9cfd694
ZJS
261 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
262
263 b = None
ccc9a4f9 264 for manpage, manvolume in sorted(set(manpages)):
827f70eb
ZJS
265 if b is not None:
266 b.tail = ', '
267 b = tree.SubElement(para, 'citerefentry')
268 c = tree.SubElement(b, 'refentrytitle')
269 c.text = manpage
270 d = tree.SubElement(b, 'manvolnum')
271 d.text = manvolume
d9cfd694
ZJS
272 entry.tail = '\n\n'
273
0acfdd61
ZJS
274def _make_colophon(template, groups):
275 count = 0
276 pages = set()
277 for group in groups:
278 count += len(group)
279 for pagelist in group.values():
280 pages |= set(pagelist)
281
282 para = template.find(".//para[@id='colophon']")
283 para.text = COLOPHON.format(count=count,
284 sections=len(groups),
285 pages=len(pages))
286
d970bd6d 287def _make_page(template, directive_groups, formatting):
d9cfd694
ZJS
288 """Create an XML tree from directive_groups.
289
290 directive_groups = {
291 'class': {'variable': [('manpage', 'manvolume'), ...],
292 'variable2': ...},
293 ...
294 }
295 """
d9cfd694 296 for name, directives in directive_groups.items():
827f70eb 297 _make_section(template, name, directives, formatting)
d9cfd694 298
0acfdd61
ZJS
299 _make_colophon(template, directive_groups.values())
300
eeb019b5 301 return template
d9cfd694 302
ccc9a4f9 303def make_page(*xml_files):
d9cfd694 304 "Extract directives from xml_files and return XML index tree."
eeb019b5
ZJS
305 template = tree.fromstring(TEMPLATE)
306 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
d9cfd694 307 directive_groups = {name:collections.defaultdict(list)
eeb019b5 308 for name in names}
d970bd6d 309 formatting = {}
d9cfd694 310 for page in xml_files:
ccc9a4f9 311 try:
d970bd6d 312 _extract_directives(directive_groups, formatting, page)
ccc9a4f9
ZJS
313 except Exception:
314 raise ValueError("failed to process " + page)
d9cfd694 315
d970bd6d 316 return _make_page(template, directive_groups, formatting)
d9cfd694
ZJS
317
318if __name__ == '__main__':
1a13e31d
ZJS
319 with open(sys.argv[1], 'wb') as f:
320 f.write(xml_print(make_page(*sys.argv[2:])))