blob: 256ff3dc5daec3fb5cab9cf5a75aeb524ca50c5f [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
Tom Gundersen46b09252013-11-10 20:52:53 +010093 net-setup-link udev builtin and networks through
94 systemd-networkd.</para>
Tom Gundersen1f068072013-11-10 19:33:18 +010095
96 <variablelist id='network-directives' />
97 </refsect1>
98
99 <refsect1>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500100 <title>Journal fields</title>
Zbigniew Jędrzejewski-Szmekf6c2e282012-08-10 19:35:43 +0200101
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500102 <para>Fields in the journal events with a well known meaning.</para>
Zbigniew Jędrzejewski-Szmekf6c2e282012-08-10 19:35:43 +0200103
104 <variablelist id='journal-directives' />
105 </refsect1>
Zbigniew Jędrzejewski-Szmek4a431c92013-01-14 20:18:36 -0500106
107 <refsect1>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500108 <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>
Zbigniew Jędrzejewski-Szmek63b03c02014-06-30 09:27:16 -0400116 <title><filename>/etc/crypttab</filename> and
117 <filename>/etc/fstab</filename> options</title>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500118
119 <para>Options which influence mounted filesystems and
120 encrypted volumes.</para>
121
Zbigniew Jędrzejewski-Szmek63b03c02014-06-30 09:27:16 -0400122 <variablelist id='fstab-options' />
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500123 </refsect1>
124
125 <refsect1>
126 <title>System manager directives</title>
127
128 <para>Directives for configuring the behaviour of the
129 systemd process.</para>
130
131 <variablelist id='systemd-directives' />
132 </refsect1>
133
134 <refsect1>
Lennart Poettering81c7dd82014-11-06 20:06:30 +0100135 <title>command line options</title>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500136
137 <para>Command-line options accepted by programs in the
138 systemd suite.</para>
139
140 <variablelist id='options' />
141 </refsect1>
142
143 <refsect1>
Zbigniew Jędrzejewski-Szmek785a51e2013-06-26 19:48:19 -0400144 <title>Constants</title>
145
146 <para>Various constant used and/or defined by systemd.</para>
147
148 <variablelist id='constants' />
149 </refsect1>
150
151 <refsect1>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500152 <title>Miscellaneous options and directives</title>
153
154 <para>Other configuration elements which don't fit in
155 any of the above groups.</para>
156
157 <variablelist id='miscellaneous' />
158 </refsect1>
159
160 <refsect1>
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500161 <title>Files and directories</title>
162
163 <para>Paths and file names referred to in the
164 documentation.</para>
165
166 <variablelist id='filenames' />
167 </refsect1>
168
169 <refsect1>
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500170 <title>Colophon</title>
171 <para id='colophon' />
172 </refsect1>
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200173</refentry>
174'''
175
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500176COLOPHON = '''\
177This index contains {count} entries in {sections} sections,
178referring to {pages} individual manual pages.
179'''
180
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500181def _extract_directives(directive_groups, formatting, page):
Zbigniew Jędrzejewski-Szmek1a13e312013-03-29 14:22:27 -0400182 t = xml_parse(page)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200183 section = t.find('./refmeta/manvolnum').text
184 pagename = t.find('./refmeta/refentrytitle').text
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500185
186 storopt = directive_groups['options']
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200187 for variablelist in t.iterfind('.//variablelist'):
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500188 klass = variablelist.attrib.get('class')
189 storvar = directive_groups[klass or 'miscellaneous']
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500190 # <option>s go in OPTIONS, unless class is specified
191 for xpath, stor in (('./varlistentry/term/varname', storvar),
192 ('./varlistentry/term/option',
193 storvar if klass else storopt)):
194 for name in variablelist.iterfind(xpath):
195 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
196 stor[text].append((pagename, section))
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500197 if text not in formatting:
198 # use element as formatted display
Zbigniew Jędrzejewski-Szmek699ad6c2013-02-27 21:31:02 -0500199 if name.text[-1] in '= ':
200 name.clear()
201 else:
202 name.tail = ''
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500203 name.text = text
204 formatting[text] = name
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200205
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500206 storfile = directive_groups['filenames']
Zbigniew Jędrzejewski-Szmek845c5322013-05-03 00:55:20 -0400207 for xpath, absolute_only in (('.//refsynopsisdiv//filename', False),
208 ('.//refsynopsisdiv//command', False),
209 ('.//filename', True)):
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500210 for name in t.iterfind(xpath):
Zbigniew Jędrzejewski-Szmek845c5322013-05-03 00:55:20 -0400211 if absolute_only and not (name.text and name.text.startswith('/')):
212 continue
213 if name.attrib.get('noindex'):
214 continue
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500215 name.tail = ''
216 if name.text:
Zbigniew Jędrzejewski-Szmek845c5322013-05-03 00:55:20 -0400217 if name.text.endswith('*'):
218 name.text = name.text[:-1]
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500219 if not name.text.startswith('.'):
220 text = name.text.partition(' ')[0]
221 if text != name.text:
222 name.clear()
223 name.text = text
Zbigniew Jędrzejewski-Szmek845c5322013-05-03 00:55:20 -0400224 if text.endswith('/'):
225 text = text[:-1]
Zbigniew Jędrzejewski-Szmeka4e0b942013-02-13 21:51:31 -0500226 storfile[text].append((pagename, section))
227 if text not in formatting:
228 # use element as formatted display
229 formatting[text] = name
230 else:
231 text = ' '.join(name.itertext())
232 storfile[text].append((pagename, section))
233 formatting[text] = name
234
Zbigniew Jędrzejewski-Szmek785a51e2013-06-26 19:48:19 -0400235 storfile = directive_groups['constants']
236 for name in t.iterfind('.//constant'):
237 if name.attrib.get('noindex'):
238 continue
239 name.tail = ''
240 if name.text.startswith('('): # a cast, strip it
241 name.text = name.text.partition(' ')[2]
242 storfile[name.text].append((pagename, section))
243 formatting[name.text] = name
244
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500245def _make_section(template, name, directives, formatting):
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500246 varlist = template.find(".//*[@id='{}']".format(name))
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200247 for varname, manpages in sorted(directives.items()):
248 entry = tree.SubElement(varlist, 'varlistentry')
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500249 term = tree.SubElement(entry, 'term')
Zbigniew Jędrzejewski-Szmek827f70e2013-05-29 22:31:20 -0400250 display = deepcopy(formatting[varname])
251 term.append(display)
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500252
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200253 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
254
255 b = None
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500256 for manpage, manvolume in sorted(set(manpages)):
Zbigniew Jędrzejewski-Szmek827f70e2013-05-29 22:31:20 -0400257 if b is not None:
258 b.tail = ', '
259 b = tree.SubElement(para, 'citerefentry')
260 c = tree.SubElement(b, 'refentrytitle')
261 c.text = manpage
Zbigniew Jędrzejewski-Szmek958caa52015-11-22 23:43:36 -0500262 c.attrib['target'] = varname
Zbigniew Jędrzejewski-Szmek827f70e2013-05-29 22:31:20 -0400263 d = tree.SubElement(b, 'manvolnum')
264 d.text = manvolume
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200265 entry.tail = '\n\n'
266
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500267def _make_colophon(template, groups):
268 count = 0
269 pages = set()
270 for group in groups:
271 count += len(group)
272 for pagelist in group.values():
273 pages |= set(pagelist)
274
275 para = template.find(".//para[@id='colophon']")
276 para.text = COLOPHON.format(count=count,
277 sections=len(groups),
278 pages=len(pages))
279
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500280def _make_page(template, directive_groups, formatting):
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200281 """Create an XML tree from directive_groups.
282
283 directive_groups = {
284 'class': {'variable': [('manpage', 'manvolume'), ...],
285 'variable2': ...},
286 ...
287 }
288 """
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200289 for name, directives in directive_groups.items():
Zbigniew Jędrzejewski-Szmek827f70e2013-05-29 22:31:20 -0400290 _make_section(template, name, directives, formatting)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200291
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500292 _make_colophon(template, directive_groups.values())
293
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500294 return template
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200295
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500296def make_page(*xml_files):
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200297 "Extract directives from xml_files and return XML index tree."
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500298 template = tree.fromstring(TEMPLATE)
299 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200300 directive_groups = {name:collections.defaultdict(list)
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500301 for name in names}
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500302 formatting = {}
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200303 for page in xml_files:
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500304 try:
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500305 _extract_directives(directive_groups, formatting, page)
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500306 except Exception:
307 raise ValueError("failed to process " + page)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200308
Zbigniew Jędrzejewski-Szmekd970bd62013-01-26 11:27:35 -0500309 return _make_page(template, directive_groups, formatting)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200310
311if __name__ == '__main__':
Zbigniew Jędrzejewski-Szmek1a13e312013-03-29 14:22:27 -0400312 with open(sys.argv[1], 'wb') as f:
313 f.write(xml_print(make_page(*sys.argv[2:])))