blob: b2dd2e1b7879a2f5977ecf0dc8d46be78cd49b46 [file] [log] [blame]
Zbigniew Jędrzejewski-Szmeke7098b62012-11-13 18:39:18 +01001# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
2#
3# This file is part of systemd.
4#
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -05005# Copyright 2012-2013 Zbigniew Jędrzejewski-Szmek
Zbigniew Jędrzejewski-Szmeke7098b62012-11-13 18:39:18 +01006#
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
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +020020import sys
21import collections
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -050022import re
Zbigniew Jędrzejewski-Szmek1a13e312013-03-29 14:22:27 -040023from xml_helper import *
Zbigniew Jędrzejewski-Szmek827f70e2013-05-29 22:31:20 -040024from copy import deepcopy
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +020025
26TEMPLATE = '''\
Zbigniew Jędrzejewski-Szmek56ba3c72013-02-02 22:47:47 -050027<refentry id="systemd.directives" conditional="HAVE_PYTHON">
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +020028
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>
Zbigniew Jędrzejewski-Szmek9cc2c8b2013-01-14 22:08:33 -050045 <manvolnum>7</manvolnum>
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +020046 </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>
Zbigniew Jędrzejewski-Szmeke1abd3e2012-09-16 11:11:34 +020061
62 <refsect1>
Zbigniew Jędrzejewski-Szmek08177c82013-01-14 21:58:22 -050063 <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
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -050068 <variablelist id='kernel-commandline-options' />
Zbigniew Jędrzejewski-Szmek08177c82013-01-14 21:58:22 -050069 </refsect1>
70
71 <refsect1>
72 <title>Environment variables</title>
73
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -050074 <para>Environment variables understood by the systemd
75 manager and other programs.</para>
Zbigniew Jędrzejewski-Szmek08177c82013-01-14 21:58:22 -050076
77 <variablelist id='environment-variables' />
78 </refsect1>
79
80 <refsect1>
Zbigniew Jędrzejewski-Szmeke1abd3e2012-09-16 11:11:34 +020081 <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>
Zbigniew Jędrzejewski-Szmekf6c2e282012-08-10 19:35:43 +020088
89 <refsect1>
Tom Gundersen1f068072013-11-10 19:33:18 +010090 <title>Network directives</title>
91
92 <para>Directives for configuring network links through the
93 net-setup-link udev builtin.</para>
94
95 <variablelist id='network-directives' />
96 </refsect1>
97
98 <refsect1>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -050099 <title>Journal fields</title>
Zbigniew Jędrzejewski-Szmekf6c2e282012-08-10 19:35:43 +0200100
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500101 <para>Fields in the journal events with a well known meaning.</para>
Zbigniew Jędrzejewski-Szmekf6c2e282012-08-10 19:35:43 +0200102
103 <variablelist id='journal-directives' />
104 </refsect1>
Zbigniew Jędrzejewski-Szmek4a431c92013-01-14 20:18:36 -0500105
106 <refsect1>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500107 <title>PAM configuration directives</title>
108
109 <para>Directives for configuring PAM behaviour.</para>
110
111 <variablelist id='pam-directives' />
112 </refsect1>
113
114 <refsect1>
115 <title>crypttab options</title>
116
117 <para>Options which influence mounted filesystems and
118 encrypted volumes.</para>
119
120 <variablelist id='crypttab-options' />
121 </refsect1>
122
123 <refsect1>
124 <title>System manager directives</title>
125
126 <para>Directives for configuring the behaviour of the
127 systemd process.</para>
128
129 <variablelist id='systemd-directives' />
130 </refsect1>
131
132 <refsect1>
Zbigniew Jędrzejewski-Szmek4a431c92013-01-14 20:18:36 -0500133 <title>bootchart.conf directives</title>
134
135 <para>Directives for configuring the behaviour of the
136 systemd-bootchart process.</para>
137
138 <variablelist id='bootchart-directives' />
139 </refsect1>
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500140
141 <refsect1>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500142 <title>command-line options</title>
143
144 <para>Command-line options accepted by programs in the
145 systemd suite.</para>
146
147 <variablelist id='options' />
148 </refsect1>
149
150 <refsect1>
Zbigniew Jędrzejewski-Szmek785a51e2013-06-26 19:48:19 -0400151 <title>Constants</title>
152
153 <para>Various constant used and/or defined by systemd.</para>
154
155 <variablelist id='constants' />
156 </refsect1>
157
158 <refsect1>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500159 <title>Miscellaneous options and directives</title>
160
161 <para>Other configuration elements which don't fit in
162 any of the above groups.</para>
163
164 <variablelist id='miscellaneous' />
165 </refsect1>
166
167 <refsect1>
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500168 <title>Files and directories</title>
169
170 <para>Paths and file names referred to in the
171 documentation.</para>
172
173 <variablelist id='filenames' />
174 </refsect1>
175
176 <refsect1>
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500177 <title>Colophon</title>
178 <para id='colophon' />
179 </refsect1>
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200180</refentry>
181'''
182
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500183COLOPHON = '''\
184This index contains {count} entries in {sections} sections,
185referring to {pages} individual manual pages.
186'''
187
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500188def _extract_directives(directive_groups, formatting, page):
Zbigniew Jędrzejewski-Szmek1a13e312013-03-29 14:22:27 -0400189 t = xml_parse(page)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200190 section = t.find('./refmeta/manvolnum').text
191 pagename = t.find('./refmeta/refentrytitle').text
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500192
193 storopt = directive_groups['options']
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200194 for variablelist in t.iterfind('.//variablelist'):
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500195 klass = variablelist.attrib.get('class')
196 storvar = directive_groups[klass or 'miscellaneous']
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500197 # <option>s go in OPTIONS, unless class is specified
198 for xpath, stor in (('./varlistentry/term/varname', storvar),
199 ('./varlistentry/term/option',
200 storvar if klass else storopt)):
201 for name in variablelist.iterfind(xpath):
202 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
203 stor[text].append((pagename, section))
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500204 if text not in formatting:
205 # use element as formatted display
Zbigniew Jędrzejewski-Szmek699ad6c2013-02-27 21:31:02 -0500206 if name.text[-1] in '= ':
207 name.clear()
208 else:
209 name.tail = ''
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500210 name.text = text
211 formatting[text] = name
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200212
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500213 storfile = directive_groups['filenames']
Zbigniew Jędrzejewski-Szmek845c5322013-05-03 00:55:20 -0400214 for xpath, absolute_only in (('.//refsynopsisdiv//filename', False),
215 ('.//refsynopsisdiv//command', False),
216 ('.//filename', True)):
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500217 for name in t.iterfind(xpath):
Zbigniew Jędrzejewski-Szmek845c5322013-05-03 00:55:20 -0400218 if absolute_only and not (name.text and name.text.startswith('/')):
219 continue
220 if name.attrib.get('noindex'):
221 continue
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500222 name.tail = ''
223 if name.text:
Zbigniew Jędrzejewski-Szmek845c5322013-05-03 00:55:20 -0400224 if name.text.endswith('*'):
225 name.text = name.text[:-1]
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500226 if not name.text.startswith('.'):
227 text = name.text.partition(' ')[0]
228 if text != name.text:
229 name.clear()
230 name.text = text
Zbigniew Jędrzejewski-Szmek845c5322013-05-03 00:55:20 -0400231 if text.endswith('/'):
232 text = text[:-1]
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500233 storfile[text].append((pagename, section))
234 if text not in formatting:
235 # use element as formatted display
236 formatting[text] = name
237 else:
238 text = ' '.join(name.itertext())
239 storfile[text].append((pagename, section))
240 formatting[text] = name
241
Zbigniew Jędrzejewski-Szmek785a51e2013-06-26 19:48:19 -0400242 storfile = directive_groups['constants']
243 for name in t.iterfind('.//constant'):
244 if name.attrib.get('noindex'):
245 continue
246 name.tail = ''
247 if name.text.startswith('('): # a cast, strip it
248 name.text = name.text.partition(' ')[2]
249 storfile[name.text].append((pagename, section))
250 formatting[name.text] = name
251
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500252def _make_section(template, name, directives, formatting):
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500253 varlist = template.find(".//*[@id='{}']".format(name))
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200254 for varname, manpages in sorted(directives.items()):
255 entry = tree.SubElement(varlist, 'varlistentry')
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500256 term = tree.SubElement(entry, 'term')
Zbigniew Jędrzejewski-Szmek827f70e2013-05-29 22:31:20 -0400257 display = deepcopy(formatting[varname])
258 term.append(display)
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500259
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200260 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
261
262 b = None
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500263 for manpage, manvolume in sorted(set(manpages)):
Zbigniew Jędrzejewski-Szmek827f70e2013-05-29 22:31:20 -0400264 if b is not None:
265 b.tail = ', '
266 b = tree.SubElement(para, 'citerefentry')
267 c = tree.SubElement(b, 'refentrytitle')
268 c.text = manpage
269 d = tree.SubElement(b, 'manvolnum')
270 d.text = manvolume
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200271 entry.tail = '\n\n'
272
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500273def _make_colophon(template, groups):
274 count = 0
275 pages = set()
276 for group in groups:
277 count += len(group)
278 for pagelist in group.values():
279 pages |= set(pagelist)
280
281 para = template.find(".//para[@id='colophon']")
282 para.text = COLOPHON.format(count=count,
283 sections=len(groups),
284 pages=len(pages))
285
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500286def _make_page(template, directive_groups, formatting):
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200287 """Create an XML tree from directive_groups.
288
289 directive_groups = {
290 'class': {'variable': [('manpage', 'manvolume'), ...],
291 'variable2': ...},
292 ...
293 }
294 """
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200295 for name, directives in directive_groups.items():
Zbigniew Jędrzejewski-Szmek827f70e2013-05-29 22:31:20 -0400296 _make_section(template, name, directives, formatting)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200297
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500298 _make_colophon(template, directive_groups.values())
299
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500300 return template
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200301
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500302def make_page(*xml_files):
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200303 "Extract directives from xml_files and return XML index tree."
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500304 template = tree.fromstring(TEMPLATE)
305 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200306 directive_groups = {name:collections.defaultdict(list)
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500307 for name in names}
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500308 formatting = {}
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200309 for page in xml_files:
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500310 try:
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500311 _extract_directives(directive_groups, formatting, page)
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500312 except Exception:
313 raise ValueError("failed to process " + page)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200314
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500315 return _make_page(template, directive_groups, formatting)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200316
317if __name__ == '__main__':
Zbigniew Jędrzejewski-Szmek1a13e312013-03-29 14:22:27 -0400318 with open(sys.argv[1], 'wb') as f:
319 f.write(xml_print(make_page(*sys.argv[2:])))