]>
git.ipfire.org Git - thirdparty/systemd.git/blob - make-directive-index.py
1 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # This file is part of systemd.
5 # Copyright 2012-2013 Zbigniew Jędrzejewski-Szmek
7 # systemd is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
12 # systemd is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 from lxml
import etree
as tree
24 PRETTY
= dict(pretty_print
=True)
26 import xml
.etree
.ElementTree
as tree
31 <refentry id="systemd.directives" conditional="HAVE_PYTHON">
34 <title>systemd.directives</title>
35 <productname>systemd</productname>
39 <contrib>Developer</contrib>
40 <firstname>Zbigniew</firstname>
41 <surname>Jędrzejewski-Szmek</surname>
42 <email>zbyszek@in.waw.pl</email>
48 <refentrytitle>systemd.directives</refentrytitle>
49 <manvolnum>7</manvolnum>
53 <refname>systemd.directives</refname>
54 <refpurpose>Index of configuration directives</refpurpose>
58 <title>Unit directives</title>
60 <para>Directives for configuring units, used in unit
63 <variablelist id='unit-directives' />
67 <title>Options on the kernel command line</title>
69 <para>Kernel boot options for configuring the behaviour of the
70 systemd process.</para>
72 <variablelist id='kernel-commandline-options' />
76 <title>Environment variables</title>
78 <para>Environment variables understood by the systemd
79 manager and other programs.</para>
81 <variablelist id='environment-variables' />
85 <title>UDEV directives</title>
87 <para>Directives for configuring systemd units through the
90 <variablelist id='udev-directives' />
94 <title>Journal fields</title>
96 <para>Fields in the journal events with a well known meaning.</para>
98 <variablelist id='journal-directives' />
102 <title>PAM configuration directives</title>
104 <para>Directives for configuring PAM behaviour.</para>
106 <variablelist id='pam-directives' />
110 <title>crypttab options</title>
112 <para>Options which influence mounted filesystems and
113 encrypted volumes.</para>
115 <variablelist id='crypttab-options' />
119 <title>System manager directives</title>
121 <para>Directives for configuring the behaviour of the
122 systemd process.</para>
124 <variablelist id='systemd-directives' />
128 <title>bootchart.conf directives</title>
130 <para>Directives for configuring the behaviour of the
131 systemd-bootchart process.</para>
133 <variablelist id='bootchart-directives' />
137 <title>command-line options</title>
139 <para>Command-line options accepted by programs in the
140 systemd suite.</para>
142 <variablelist id='options' />
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 stor
[text
].append((pagename
, section
))
191 if text
not in formatting
:
192 # use element as formatted display
193 if name
.text
[-1] in '= ':
198 formatting
[text
] = name
200 storfile
= directive_groups
['filenames']
201 for xpath
in ('.//refsynopsisdiv//filename',
202 './/refsynopsisdiv//command'):
203 for name
in t
.iterfind(xpath
):
206 if not name
.text
.startswith('.'):
207 text
= name
.text
.partition(' ')[0]
208 if text
!= name
.text
:
211 storfile
[text
].append((pagename
, section
))
212 if text
not in formatting
:
213 # use element as formatted display
214 formatting
[text
] = name
216 text
= ' '.join(name
.itertext())
217 storfile
[text
].append((pagename
, section
))
218 formatting
[text
] = name
220 def _make_section(template
, name
, directives
, formatting
):
221 varlist
= template
.find(".//*[@id='{}']".format(name
))
222 for varname
, manpages
in sorted(directives
.items()):
223 entry
= tree
.SubElement(varlist
, 'varlistentry')
224 term
= tree
.SubElement(entry
, 'term')
225 term
.append(formatting
[varname
])
227 para
= tree
.SubElement(tree
.SubElement(entry
, 'listitem'), 'para')
230 for manpage
, manvolume
in sorted(set(manpages
)):
233 b
= tree
.SubElement(para
, 'citerefentry')
234 c
= tree
.SubElement(b
, 'refentrytitle')
236 d
= tree
.SubElement(b
, 'manvolnum')
240 def _make_colophon(template
, groups
):
245 for pagelist
in group
.values():
246 pages |
= set(pagelist
)
248 para
= template
.find(".//para[@id='colophon']")
249 para
.text
= COLOPHON
.format(count
=count
,
250 sections
=len(groups
),
253 def _make_page(template
, directive_groups
, formatting
):
254 """Create an XML tree from directive_groups.
257 'class': {'variable': [('manpage', 'manvolume'), ...],
262 for name
, directives
in directive_groups
.items():
263 _make_section(template
, name
, directives
, formatting
)
265 _make_colophon(template
, directive_groups
.values())
269 def make_page(*xml_files
):
270 "Extract directives from xml_files and return XML index tree."
271 template
= tree
.fromstring(TEMPLATE
)
272 names
= [vl
.get('id') for vl
in template
.iterfind('.//variablelist')]
273 directive_groups
= {name
:collections
.defaultdict(list)
276 for page
in xml_files
:
278 _extract_directives(directive_groups
, formatting
, page
)
280 raise ValueError("failed to process " + page
)
282 return _make_page(template
, directive_groups
, formatting
)
284 if __name__
== '__main__':
285 tree
.dump(make_page(*sys
.argv
[1:]), **PRETTY
)