]>
git.ipfire.org Git - thirdparty/systemd.git/blob - tools/make-directive-index.py
2 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # SPDX-License-Identifier: LGPL-2.1+
8 from xml_helper
import xml_parse
, xml_print
, tree
9 from copy
import deepcopy
12 <refentry id="systemd.directives" conditional="HAVE_PYTHON">
15 <title>systemd.directives</title>
16 <productname>systemd</productname>
20 <refentrytitle>systemd.directives</refentrytitle>
21 <manvolnum>7</manvolnum>
25 <refname>systemd.directives</refname>
26 <refpurpose>Index of configuration directives</refpurpose>
30 <title>Unit directives</title>
32 <para>Directives for configuring units, used in unit
35 <variablelist id='unit-directives' />
39 <title>Options on the kernel command line</title>
41 <para>Kernel boot options for configuring the behaviour of the
42 systemd process.</para>
44 <variablelist id='kernel-commandline-options' />
48 <title>Environment variables</title>
50 <para>Environment variables understood by the systemd
51 manager and other programs.</para>
53 <variablelist id='environment-variables' />
57 <title>UDEV directives</title>
59 <para>Directives for configuring systemd units through the
62 <variablelist id='udev-directives' />
66 <title>Network directives</title>
68 <para>Directives for configuring network links through the
69 net-setup-link udev builtin and networks through
70 systemd-networkd.</para>
72 <variablelist id='network-directives' />
76 <title>Journal fields</title>
78 <para>Fields in the journal events with a well known meaning.</para>
80 <variablelist id='journal-directives' />
84 <title>PAM configuration directives</title>
86 <para>Directives for configuring PAM behaviour.</para>
88 <variablelist id='pam-directives' />
92 <title><filename>/etc/crypttab</filename> and
93 <filename>/etc/fstab</filename> options</title>
95 <para>Options which influence mounted filesystems and
96 encrypted volumes.</para>
98 <variablelist id='fstab-options' />
102 <title>System manager directives</title>
104 <para>Directives for configuring the behaviour of the
105 systemd process.</para>
107 <variablelist id='systemd-directives' />
111 <title>command line options</title>
113 <para>Command-line options accepted by programs in the
114 systemd suite.</para>
116 <variablelist id='options' />
120 <title>Constants</title>
122 <para>Various constant used and/or defined by systemd.</para>
124 <variablelist id='constants' />
128 <title>Miscellaneous options and directives</title>
130 <para>Other configuration elements which don't fit in
131 any of the above groups.</para>
133 <variablelist id='miscellaneous' />
137 <title>Files and directories</title>
139 <para>Paths and file names referred to in the
140 documentation.</para>
142 <variablelist id='filenames' />
146 <title>Colophon</title>
147 <para id='colophon' />
153 This index contains {count} entries in {sections} sections,
154 referring to {pages} individual manual pages.
157 def _extract_directives(directive_groups
, formatting
, page
):
159 section
= t
.find('./refmeta/manvolnum').text
160 pagename
= t
.find('./refmeta/refentrytitle').text
162 storopt
= directive_groups
['options']
163 for variablelist
in t
.iterfind('.//variablelist'):
164 klass
= variablelist
.attrib
.get('class')
165 storvar
= directive_groups
[klass
or 'miscellaneous']
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
))
173 if text
not in formatting
:
174 # use element as formatted display
175 if name
.text
[-1] in '= ':
180 formatting
[text
] = name
182 storfile
= directive_groups
['filenames']
183 for xpath
, absolute_only
in (('.//refsynopsisdiv//filename', False),
184 ('.//refsynopsisdiv//command', False),
185 ('.//filename', True)):
186 for name
in t
.iterfind(xpath
):
187 if absolute_only
and not (name
.text
and name
.text
.startswith('/')):
189 if name
.attrib
.get('noindex'):
193 if name
.text
.endswith('*'):
194 name
.text
= name
.text
[:-1]
195 if not name
.text
.startswith('.'):
196 text
= name
.text
.partition(' ')[0]
197 if text
!= name
.text
:
200 if text
.endswith('/'):
202 storfile
[text
].append((pagename
, section
))
203 if text
not in formatting
:
204 # use element as formatted display
205 formatting
[text
] = name
207 text
= ' '.join(name
.itertext())
208 storfile
[text
].append((pagename
, section
))
209 formatting
[text
] = name
211 storfile
= directive_groups
['constants']
212 for name
in t
.iterfind('.//constant'):
213 if name
.attrib
.get('noindex'):
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
221 def _make_section(template
, name
, directives
, formatting
):
222 varlist
= template
.find(".//*[@id='{}']".format(name
))
223 for varname
, manpages
in sorted(directives
.items()):
224 entry
= tree
.SubElement(varlist
, 'varlistentry')
225 term
= tree
.SubElement(entry
, 'term')
226 display
= deepcopy(formatting
[varname
])
229 para
= tree
.SubElement(tree
.SubElement(entry
, 'listitem'), 'para')
232 for manpage
, manvolume
in sorted(set(manpages
)):
235 b
= tree
.SubElement(para
, 'citerefentry')
236 c
= tree
.SubElement(b
, 'refentrytitle')
238 c
.attrib
['target'] = varname
239 d
= tree
.SubElement(b
, 'manvolnum')
243 def _make_colophon(template
, groups
):
248 for pagelist
in group
.values():
249 pages |
= set(pagelist
)
251 para
= template
.find(".//para[@id='colophon']")
252 para
.text
= COLOPHON
.format(count
=count
,
253 sections
=len(groups
),
256 def _make_page(template
, directive_groups
, formatting
):
257 """Create an XML tree from directive_groups.
260 'class': {'variable': [('manpage', 'manvolume'), ...],
265 for name
, directives
in directive_groups
.items():
266 _make_section(template
, name
, directives
, formatting
)
268 _make_colophon(template
, directive_groups
.values())
272 def make_page(*xml_files
):
273 "Extract directives from xml_files and return XML index tree."
274 template
= tree
.fromstring(TEMPLATE
)
275 names
= [vl
.get('id') for vl
in template
.iterfind('.//variablelist')]
276 directive_groups
= {name
:collections
.defaultdict(list)
279 for page
in xml_files
:
281 _extract_directives(directive_groups
, formatting
, page
)
283 raise ValueError("failed to process " + page
)
285 return _make_page(template
, directive_groups
, formatting
)
287 if __name__
== '__main__':
288 with
open(sys
.argv
[1], 'wb') as f
:
289 f
.write(xml_print(make_page(*sys
.argv
[2:])))