]>
git.ipfire.org Git - thirdparty/systemd.git/blob - tools/make-directive-index.py
2 # SPDX-License-Identifier: LGPL-2.1+
7 from xml_helper
import xml_parse
, xml_print
, tree
8 from copy
import deepcopy
11 <refentry id="systemd.directives" conditional="HAVE_PYTHON">
14 <title>systemd.directives</title>
15 <productname>systemd</productname>
19 <refentrytitle>systemd.directives</refentrytitle>
20 <manvolnum>7</manvolnum>
24 <refname>systemd.directives</refname>
25 <refpurpose>Index of configuration directives</refpurpose>
29 <title>Unit directives</title>
31 <para>Directives for configuring units, used in unit
34 <variablelist id='unit-directives' />
38 <title>Options on the kernel command line</title>
40 <para>Kernel boot options for configuring the behaviour of the
41 systemd process.</para>
43 <variablelist id='kernel-commandline-options' />
47 <title>Environment variables</title>
49 <para>Environment variables understood by the systemd manager
50 and other programs and environment variable-compatible settings.</para>
52 <variablelist id='environment-variables' />
56 <title>EFI variables</title>
58 <para>EFI variables understood by
59 <citerefentry><refentrytitle>systemd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry>
60 and other programs.</para>
62 <variablelist id='efi-variables' />
66 <title>UDEV directives</title>
68 <para>Directives for configuring systemd units through the
71 <variablelist id='udev-directives' />
75 <title>Network directives</title>
77 <para>Directives for configuring network links through the
78 net-setup-link udev builtin and networks through
79 systemd-networkd.</para>
81 <variablelist id='network-directives' />
85 <title>Journal fields</title>
87 <para>Fields in the journal events with a well known meaning.</para>
89 <variablelist id='journal-directives' />
93 <title>PAM configuration directives</title>
95 <para>Directives for configuring PAM behaviour.</para>
97 <variablelist id='pam-directives' />
101 <title><filename>/etc/crypttab</filename> and
102 <filename>/etc/fstab</filename> options</title>
104 <para>Options which influence mounted filesystems and
105 encrypted volumes.</para>
107 <variablelist id='fstab-options' />
111 <title><citerefentry><refentrytitle>systemd.nspawn</refentrytitle><manvolnum>5</manvolnum></citerefentry>
114 <para>Directives for configuring systemd-nspawn containers.</para>
116 <variablelist id='nspawn-directives' />
120 <title>Program configuration options</title>
122 <para>Directives for configuring the behaviour of the
123 systemd process and other tools through configuration files.</para>
125 <variablelist id='config-directives' />
129 <title>Command line options</title>
131 <para>Command-line options accepted by programs in the
132 systemd suite.</para>
134 <variablelist id='options' />
138 <title>Constants</title>
140 <para>Various constant used and/or defined by systemd.</para>
142 <variablelist id='constants' />
146 <title>Miscellaneous options and directives</title>
148 <para>Other configuration elements which don't fit in
149 any of the above groups.</para>
151 <variablelist id='miscellaneous' />
155 <title>Files and directories</title>
157 <para>Paths and file names referred to in the
158 documentation.</para>
160 <variablelist id='filenames' />
164 <title>Colophon</title>
165 <para id='colophon' />
171 This index contains {count} entries in {sections} sections,
172 referring to {pages} individual manual pages.
175 def _extract_directives(directive_groups
, formatting
, page
):
177 section
= t
.find('./refmeta/manvolnum').text
178 pagename
= t
.find('./refmeta/refentrytitle').text
180 storopt
= directive_groups
['options']
181 for variablelist
in t
.iterfind('.//variablelist'):
182 klass
= variablelist
.attrib
.get('class')
183 storvar
= directive_groups
[klass
or 'miscellaneous']
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 if text
.startswith('-'):
191 # for options, merge options with and without mandatory arg
192 text
= text
.partition('=')[0]
193 stor
[text
].append((pagename
, section
))
194 if text
not in formatting
:
195 # use element as formatted display
196 if name
.text
[-1] in "= '":
201 formatting
[text
] = name
203 storfile
= directive_groups
['filenames']
204 for xpath
, absolute_only
in (('.//refsynopsisdiv//filename', False),
205 ('.//refsynopsisdiv//command', False),
206 ('.//filename', True)):
207 for name
in t
.iterfind(xpath
):
208 if absolute_only
and not (name
.text
and name
.text
.startswith('/')):
210 if name
.attrib
.get('index') == 'false':
214 if name
.text
.endswith('*'):
215 name
.text
= name
.text
[:-1]
216 if not name
.text
.startswith('.'):
217 text
= name
.text
.partition(' ')[0]
218 if text
!= name
.text
:
221 if text
.endswith('/'):
223 storfile
[text
].append((pagename
, section
))
224 if text
not in formatting
:
225 # use element as formatted display
226 formatting
[text
] = name
228 text
= ' '.join(name
.itertext())
229 storfile
[text
].append((pagename
, section
))
230 formatting
[text
] = name
232 storfile
= directive_groups
['constants']
233 for name
in t
.iterfind('.//constant'):
234 if name
.attrib
.get('index') == 'false':
237 if name
.text
.startswith('('): # a cast, strip it
238 name
.text
= name
.text
.partition(' ')[2]
239 storfile
[name
.text
].append((pagename
, section
))
240 formatting
[name
.text
] = name
242 def _make_section(template
, name
, directives
, formatting
):
243 varlist
= template
.find(".//*[@id='{}']".format(name
))
244 for varname
, manpages
in sorted(directives
.items()):
245 entry
= tree
.SubElement(varlist
, 'varlistentry')
246 term
= tree
.SubElement(entry
, 'term')
247 display
= deepcopy(formatting
[varname
])
250 para
= tree
.SubElement(tree
.SubElement(entry
, 'listitem'), 'para')
253 for manpage
, manvolume
in sorted(set(manpages
)):
256 b
= tree
.SubElement(para
, 'citerefentry')
257 c
= tree
.SubElement(b
, 'refentrytitle')
259 c
.attrib
['target'] = varname
260 d
= tree
.SubElement(b
, 'manvolnum')
264 def _make_colophon(template
, groups
):
269 for pagelist
in group
.values():
270 pages |
= set(pagelist
)
272 para
= template
.find(".//para[@id='colophon']")
273 para
.text
= COLOPHON
.format(count
=count
,
274 sections
=len(groups
),
277 def _make_page(template
, directive_groups
, formatting
):
278 """Create an XML tree from directive_groups.
281 'class': {'variable': [('manpage', 'manvolume'), ...],
286 for name
, directives
in directive_groups
.items():
287 _make_section(template
, name
, directives
, formatting
)
289 _make_colophon(template
, directive_groups
.values())
293 def make_page(*xml_files
):
294 "Extract directives from xml_files and return XML index tree."
295 template
= tree
.fromstring(TEMPLATE
)
296 names
= [vl
.get('id') for vl
in template
.iterfind('.//variablelist')]
297 directive_groups
= {name
:collections
.defaultdict(list)
300 for page
in xml_files
:
302 _extract_directives(directive_groups
, formatting
, page
)
304 raise ValueError("failed to process " + page
)
306 return _make_page(template
, directive_groups
, formatting
)
308 if __name__
== '__main__':
309 with
open(sys
.argv
[1], 'wb') as f
:
310 f
.write(xml_print(make_page(*sys
.argv
[2:])))