]>
git.ipfire.org Git - thirdparty/systemd.git/blob - tools/make-directive-index.py
2 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
4 # This file is part of systemd.
6 # Copyright 2012-2013 Zbigniew Jędrzejewski-Szmek
8 # systemd is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation; either version 2.1 of the License, or
11 # (at your option) any later version.
13 # systemd is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 from xml_helper
import xml_parse
, xml_print
, tree
25 from copy
import deepcopy
28 <refentry id="systemd.directives" conditional="HAVE_PYTHON">
31 <title>systemd.directives</title>
32 <productname>systemd</productname>
36 <contrib>Developer</contrib>
37 <firstname>Zbigniew</firstname>
38 <surname>Jędrzejewski-Szmek</surname>
39 <email>zbyszek@in.waw.pl</email>
45 <refentrytitle>systemd.directives</refentrytitle>
46 <manvolnum>7</manvolnum>
50 <refname>systemd.directives</refname>
51 <refpurpose>Index of configuration directives</refpurpose>
55 <title>Unit directives</title>
57 <para>Directives for configuring units, used in unit
60 <variablelist id='unit-directives' />
64 <title>Options on the kernel command line</title>
66 <para>Kernel boot options for configuring the behaviour of the
67 systemd process.</para>
69 <variablelist id='kernel-commandline-options' />
73 <title>Environment variables</title>
75 <para>Environment variables understood by the systemd
76 manager and other programs.</para>
78 <variablelist id='environment-variables' />
82 <title>UDEV directives</title>
84 <para>Directives for configuring systemd units through the
87 <variablelist id='udev-directives' />
91 <title>Network directives</title>
93 <para>Directives for configuring network links through the
94 net-setup-link udev builtin and networks through
95 systemd-networkd.</para>
97 <variablelist id='network-directives' />
101 <title>Journal fields</title>
103 <para>Fields in the journal events with a well known meaning.</para>
105 <variablelist id='journal-directives' />
109 <title>PAM configuration directives</title>
111 <para>Directives for configuring PAM behaviour.</para>
113 <variablelist id='pam-directives' />
117 <title><filename>/etc/crypttab</filename> and
118 <filename>/etc/fstab</filename> options</title>
120 <para>Options which influence mounted filesystems and
121 encrypted volumes.</para>
123 <variablelist id='fstab-options' />
127 <title>System manager directives</title>
129 <para>Directives for configuring the behaviour of the
130 systemd process.</para>
132 <variablelist id='systemd-directives' />
136 <title>command line options</title>
138 <para>Command-line options accepted by programs in the
139 systemd suite.</para>
141 <variablelist id='options' />
145 <title>Constants</title>
147 <para>Various constant used and/or defined by systemd.</para>
149 <variablelist id='constants' />
153 <title>Miscellaneous options and directives</title>
155 <para>Other configuration elements which don't fit in
156 any of the above groups.</para>
158 <variablelist id='miscellaneous' />
162 <title>Files and directories</title>
164 <para>Paths and file names referred to in the
165 documentation.</para>
167 <variablelist id='filenames' />
171 <title>Colophon</title>
172 <para id='colophon' />
178 This index contains {count} entries in {sections} sections,
179 referring to {pages} individual manual pages.
182 def _extract_directives(directive_groups
, formatting
, page
):
184 section
= t
.find('./refmeta/manvolnum').text
185 pagename
= t
.find('./refmeta/refentrytitle').text
187 storopt
= directive_groups
['options']
188 for variablelist
in t
.iterfind('.//variablelist'):
189 klass
= variablelist
.attrib
.get('class')
190 storvar
= directive_groups
[klass
or 'miscellaneous']
191 # <option>s go in OPTIONS, unless class is specified
192 for xpath
, stor
in (('./varlistentry/term/varname', storvar
),
193 ('./varlistentry/term/option',
194 storvar
if klass
else storopt
)):
195 for name
in variablelist
.iterfind(xpath
):
196 text
= re
.sub(r
'([= ]).*', r
'\1', name
.text
).rstrip()
197 stor
[text
].append((pagename
, section
))
198 if text
not in formatting
:
199 # use element as formatted display
200 if name
.text
[-1] in '= ':
205 formatting
[text
] = name
207 storfile
= directive_groups
['filenames']
208 for xpath
, absolute_only
in (('.//refsynopsisdiv//filename', False),
209 ('.//refsynopsisdiv//command', False),
210 ('.//filename', True)):
211 for name
in t
.iterfind(xpath
):
212 if absolute_only
and not (name
.text
and name
.text
.startswith('/')):
214 if name
.attrib
.get('noindex'):
218 if name
.text
.endswith('*'):
219 name
.text
= name
.text
[:-1]
220 if not name
.text
.startswith('.'):
221 text
= name
.text
.partition(' ')[0]
222 if text
!= name
.text
:
225 if text
.endswith('/'):
227 storfile
[text
].append((pagename
, section
))
228 if text
not in formatting
:
229 # use element as formatted display
230 formatting
[text
] = name
232 text
= ' '.join(name
.itertext())
233 storfile
[text
].append((pagename
, section
))
234 formatting
[text
] = name
236 storfile
= directive_groups
['constants']
237 for name
in t
.iterfind('.//constant'):
238 if name
.attrib
.get('noindex'):
241 if name
.text
.startswith('('): # a cast, strip it
242 name
.text
= name
.text
.partition(' ')[2]
243 storfile
[name
.text
].append((pagename
, section
))
244 formatting
[name
.text
] = name
246 def _make_section(template
, name
, directives
, formatting
):
247 varlist
= template
.find(".//*[@id='{}']".format(name
))
248 for varname
, manpages
in sorted(directives
.items()):
249 entry
= tree
.SubElement(varlist
, 'varlistentry')
250 term
= tree
.SubElement(entry
, 'term')
251 display
= deepcopy(formatting
[varname
])
254 para
= tree
.SubElement(tree
.SubElement(entry
, 'listitem'), 'para')
257 for manpage
, manvolume
in sorted(set(manpages
)):
260 b
= tree
.SubElement(para
, 'citerefentry')
261 c
= tree
.SubElement(b
, 'refentrytitle')
263 c
.attrib
['target'] = varname
264 d
= tree
.SubElement(b
, 'manvolnum')
268 def _make_colophon(template
, groups
):
273 for pagelist
in group
.values():
274 pages |
= set(pagelist
)
276 para
= template
.find(".//para[@id='colophon']")
277 para
.text
= COLOPHON
.format(count
=count
,
278 sections
=len(groups
),
281 def _make_page(template
, directive_groups
, formatting
):
282 """Create an XML tree from directive_groups.
285 'class': {'variable': [('manpage', 'manvolume'), ...],
290 for name
, directives
in directive_groups
.items():
291 _make_section(template
, name
, directives
, formatting
)
293 _make_colophon(template
, directive_groups
.values())
297 def make_page(*xml_files
):
298 "Extract directives from xml_files and return XML index tree."
299 template
= tree
.fromstring(TEMPLATE
)
300 names
= [vl
.get('id') for vl
in template
.iterfind('.//variablelist')]
301 directive_groups
= {name
:collections
.defaultdict(list)
304 for page
in xml_files
:
306 _extract_directives(directive_groups
, formatting
, page
)
308 raise ValueError("failed to process " + page
)
310 return _make_page(template
, directive_groups
, formatting
)
312 if __name__
== '__main__':
313 with
open(sys
.argv
[1], 'wb') as f
:
314 f
.write(xml_print(make_page(*sys
.argv
[2:])))