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