blob: 29c594cb750183b5ed6db9fc0d71f6b0f52f0c8c [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
22import xml.etree.ElementTree as tree
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -050023import re
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +020024
25TEMPLATE = '''\
26<refentry id="systemd.directives">
27
28 <refentryinfo>
29 <title>systemd.directives</title>
30 <productname>systemd</productname>
31
32 <authorgroup>
33 <author>
34 <contrib>Developer</contrib>
35 <firstname>Zbigniew</firstname>
36 <surname>Jędrzejewski-Szmek</surname>
37 <email>zbyszek@in.waw.pl</email>
38 </author>
39 </authorgroup>
40 </refentryinfo>
41
42 <refmeta>
43 <refentrytitle>systemd.directives</refentrytitle>
Zbigniew Jędrzejewski-Szmek9cc2c8b2013-01-14 22:08:33 -050044 <manvolnum>7</manvolnum>
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +020045 </refmeta>
46
47 <refnamediv>
48 <refname>systemd.directives</refname>
49 <refpurpose>Index of configuration directives</refpurpose>
50 </refnamediv>
51
52 <refsect1>
53 <title>Unit directives</title>
54
55 <para>Directives for configuring units, used in unit
56 files.</para>
57
58 <variablelist id='unit-directives' />
59 </refsect1>
Zbigniew Jędrzejewski-Szmeke1abd3e2012-09-16 11:11:34 +020060
61 <refsect1>
Zbigniew Jędrzejewski-Szmek08177c82013-01-14 21:58:22 -050062 <title>Options on the kernel command line</title>
63
64 <para>Kernel boot options for configuring the behaviour of the
65 systemd process.</para>
66
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -050067 <variablelist id='kernel-commandline-options' />
Zbigniew Jędrzejewski-Szmek08177c82013-01-14 21:58:22 -050068 </refsect1>
69
70 <refsect1>
71 <title>Environment variables</title>
72
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -050073 <para>Environment variables understood by the systemd
74 manager and other programs.</para>
Zbigniew Jędrzejewski-Szmek08177c82013-01-14 21:58:22 -050075
76 <variablelist id='environment-variables' />
77 </refsect1>
78
79 <refsect1>
Zbigniew Jędrzejewski-Szmeke1abd3e2012-09-16 11:11:34 +020080 <title>UDEV directives</title>
81
82 <para>Directives for configuring systemd units through the
83 udev database.</para>
84
85 <variablelist id='udev-directives' />
86 </refsect1>
Zbigniew Jędrzejewski-Szmekf6c2e282012-08-10 19:35:43 +020087
88 <refsect1>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -050089 <title>Journal fields</title>
Zbigniew Jędrzejewski-Szmekf6c2e282012-08-10 19:35:43 +020090
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -050091 <para>Fields in the journal events with a well known meaning.</para>
Zbigniew Jędrzejewski-Szmekf6c2e282012-08-10 19:35:43 +020092
93 <variablelist id='journal-directives' />
94 </refsect1>
Zbigniew Jędrzejewski-Szmek4a431c92013-01-14 20:18:36 -050095
96 <refsect1>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -050097 <title>PAM configuration directives</title>
98
99 <para>Directives for configuring PAM behaviour.</para>
100
101 <variablelist id='pam-directives' />
102 </refsect1>
103
104 <refsect1>
105 <title>crypttab options</title>
106
107 <para>Options which influence mounted filesystems and
108 encrypted volumes.</para>
109
110 <variablelist id='crypttab-options' />
111 </refsect1>
112
113 <refsect1>
114 <title>System manager directives</title>
115
116 <para>Directives for configuring the behaviour of the
117 systemd process.</para>
118
119 <variablelist id='systemd-directives' />
120 </refsect1>
121
122 <refsect1>
Zbigniew Jędrzejewski-Szmek4a431c92013-01-14 20:18:36 -0500123 <title>bootchart.conf directives</title>
124
125 <para>Directives for configuring the behaviour of the
126 systemd-bootchart process.</para>
127
128 <variablelist id='bootchart-directives' />
129 </refsect1>
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500130
131 <refsect1>
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500132 <title>command-line options</title>
133
134 <para>Command-line options accepted by programs in the
135 systemd suite.</para>
136
137 <variablelist id='options' />
138 </refsect1>
139
140 <refsect1>
141 <title>Miscellaneous options and directives</title>
142
143 <para>Other configuration elements which don't fit in
144 any of the above groups.</para>
145
146 <variablelist id='miscellaneous' />
147 </refsect1>
148
149 <refsect1>
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500150 <title>Colophon</title>
151 <para id='colophon' />
152 </refsect1>
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200153</refentry>
154'''
155
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500156COLOPHON = '''\
157This index contains {count} entries in {sections} sections,
158referring to {pages} individual manual pages.
159'''
160
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200161def _extract_directives(directive_groups, page):
162 t = tree.parse(page)
163 section = t.find('./refmeta/manvolnum').text
164 pagename = t.find('./refmeta/refentrytitle').text
165 for variablelist in t.iterfind('.//variablelist'):
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500166 klass = variablelist.attrib.get('class')
167 storvar = directive_groups[klass or 'miscellaneous']
168 storopt = directive_groups['options']
169 # <option>s go in OPTIONS, unless class is specified
170 for xpath, stor in (('./varlistentry/term/varname', storvar),
171 ('./varlistentry/term/option',
172 storvar if klass else storopt)):
173 for name in variablelist.iterfind(xpath):
174 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
175 stor[text].append((pagename, section))
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200176
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500177def _make_section(template, name, directives):
178 varlist = template.find(".//*[@id='{}']".format(name))
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200179 for varname, manpages in sorted(directives.items()):
180 entry = tree.SubElement(varlist, 'varlistentry')
181 a = tree.SubElement(tree.SubElement(entry, 'term'), 'varname')
182 a.text = varname
183 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
184
185 b = None
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500186 for manpage, manvolume in sorted(set(manpages)):
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200187 if b is not None:
188 b.tail = ', '
189 b = tree.SubElement(para, 'citerefentry')
190 c = tree.SubElement(b, 'refentrytitle')
191 c.text = manpage
192 d = tree.SubElement(b, 'manvolnum')
193 d.text = manvolume
194 entry.tail = '\n\n'
195
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500196def _make_colophon(template, groups):
197 count = 0
198 pages = set()
199 for group in groups:
200 count += len(group)
201 for pagelist in group.values():
202 pages |= set(pagelist)
203
204 para = template.find(".//para[@id='colophon']")
205 para.text = COLOPHON.format(count=count,
206 sections=len(groups),
207 pages=len(pages))
208
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500209def _make_page(template, directive_groups):
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200210 """Create an XML tree from directive_groups.
211
212 directive_groups = {
213 'class': {'variable': [('manpage', 'manvolume'), ...],
214 'variable2': ...},
215 ...
216 }
217 """
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200218 for name, directives in directive_groups.items():
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500219 _make_section(template, name, directives)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200220
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500221 _make_colophon(template, directive_groups.values())
222
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500223 return template
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200224
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500225def make_page(*xml_files):
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200226 "Extract directives from xml_files and return XML index tree."
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500227 template = tree.fromstring(TEMPLATE)
228 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200229 directive_groups = {name:collections.defaultdict(list)
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500230 for name in names}
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200231 for page in xml_files:
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500232 try:
233 _extract_directives(directive_groups, page)
234 except Exception:
235 raise ValueError("failed to process " + page)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200236
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500237 return _make_page(template, directive_groups)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200238
239if __name__ == '__main__':
Zbigniew Jędrzejewski-Szmekccc9a4f2013-01-26 10:47:16 -0500240 tree.dump(make_page(*sys.argv[1:]))