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