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