2 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # SPDX-License-Identifier: LGPL-2.1+
5 # This file is part of elogind.
7 # Copyright 2012-2013 Zbigniew Jędrzejewski-Szmek
9 # elogind is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU Lesser General Public License as published by
11 # the Free Software Foundation; either version 2.1 of the License, or
12 # (at your option) any later version.
14 # elogind is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public License
20 # along with elogind; If not, see <http://www.gnu.org/licenses/>.
25 from xml_helper import xml_parse, xml_print, tree
26 from copy import deepcopy
29 <refentry id="elogind.directives" conditional="HAVE_PYTHON">
32 <title>elogind.directives</title>
33 <productname>elogind</productname>
37 <contrib>Developer</contrib>
38 <firstname>Zbigniew</firstname>
39 <surname>Jędrzejewski-Szmek</surname>
40 <email>zbyszek@in.waw.pl</email>
46 <refentrytitle>elogind.directives</refentrytitle>
47 <manvolnum>7</manvolnum>
51 <refname>elogind.directives</refname>
52 <refpurpose>Index of configuration directives</refpurpose>
56 <title>Unit directives</title>
58 <para>Directives for configuring units, used in unit
61 <variablelist id='unit-directives' />
65 <title>Options on the kernel command line</title>
67 <para>Kernel boot options for configuring the behaviour of the
68 elogind process.</para>
70 <variablelist id='kernel-commandline-options' />
74 <title>Environment variables</title>
76 <para>Environment variables understood by the elogind
77 manager and other programs.</para>
79 <variablelist id='environment-variables' />
83 <title>UDEV directives</title>
85 <para>Directives for configuring elogind units through the
88 <variablelist id='udev-directives' />
92 <title>Network directives</title>
94 <para>Directives for configuring network links through the
95 net-setup-link udev builtin and networks through
96 elogind-networkd.</para>
98 <variablelist id='network-directives' />
102 <title>Journal fields</title>
104 <para>Fields in the journal events with a well known meaning.</para>
106 <variablelist id='journal-directives' />
110 <title>PAM configuration directives</title>
112 <para>Directives for configuring PAM behaviour.</para>
114 <variablelist id='pam-directives' />
118 <title><filename>/etc/crypttab</filename> and
119 <filename>/etc/fstab</filename> options</title>
121 <para>Options which influence mounted filesystems and
122 encrypted volumes.</para>
124 <variablelist id='fstab-options' />
128 <title>System manager directives</title>
130 <para>Directives for configuring the behaviour of the
131 elogind process.</para>
133 <variablelist id='elogind-directives' />
137 <title>command line options</title>
139 <para>Command-line options accepted by programs in the
140 elogind suite.</para>
142 <variablelist id='options' />
146 <title>Constants</title>
148 <para>Various constant used and/or defined by elogind.</para>
150 <variablelist id='constants' />
154 <title>Miscellaneous options and directives</title>
156 <para>Other configuration elements which don't fit in
157 any of the above groups.</para>
159 <variablelist id='miscellaneous' />
163 <title>Files and directories</title>
165 <para>Paths and file names referred to in the
166 documentation.</para>
168 <variablelist id='filenames' />
172 <title>Colophon</title>
173 <para id='colophon' />
179 This index contains {count} entries in {sections} sections,
180 referring to {pages} individual manual pages.
183 def _extract_directives(directive_groups, formatting, page):
185 section = t.find('./refmeta/manvolnum').text
186 pagename = t.find('./refmeta/refentrytitle').text
188 storopt = directive_groups['options']
189 for variablelist in t.iterfind('.//variablelist'):
190 klass = variablelist.attrib.get('class')
191 storvar = directive_groups[klass or 'miscellaneous']
192 # <option>s go in OPTIONS, unless class is specified
193 for xpath, stor in (('./varlistentry/term/varname', storvar),
194 ('./varlistentry/term/option',
195 storvar if klass else storopt)):
196 for name in variablelist.iterfind(xpath):
197 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
198 stor[text].append((pagename, section))
199 if text not in formatting:
200 # use element as formatted display
201 if name.text[-1] in '= ':
206 formatting[text] = name
208 storfile = directive_groups['filenames']
209 for xpath, absolute_only in (('.//refsynopsisdiv//filename', False),
210 ('.//refsynopsisdiv//command', False),
211 ('.//filename', True)):
212 for name in t.iterfind(xpath):
213 if absolute_only and not (name.text and name.text.startswith('/')):
215 if name.attrib.get('noindex'):
219 if name.text.endswith('*'):
220 name.text = name.text[:-1]
221 if not name.text.startswith('.'):
222 text = name.text.partition(' ')[0]
223 if text != name.text:
226 if text.endswith('/'):
228 storfile[text].append((pagename, section))
229 if text not in formatting:
230 # use element as formatted display
231 formatting[text] = name
233 text = ' '.join(name.itertext())
234 storfile[text].append((pagename, section))
235 formatting[text] = name
237 storfile = directive_groups['constants']
238 for name in t.iterfind('.//constant'):
239 if name.attrib.get('noindex'):
242 if name.text.startswith('('): # a cast, strip it
243 name.text = name.text.partition(' ')[2]
244 storfile[name.text].append((pagename, section))
245 formatting[name.text] = name
247 def _make_section(template, name, directives, formatting):
248 varlist = template.find(".//*[@id='{}']".format(name))
249 for varname, manpages in sorted(directives.items()):
250 entry = tree.SubElement(varlist, 'varlistentry')
251 term = tree.SubElement(entry, 'term')
252 display = deepcopy(formatting[varname])
255 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
258 for manpage, manvolume in sorted(set(manpages)):
261 b = tree.SubElement(para, 'citerefentry')
262 c = tree.SubElement(b, 'refentrytitle')
264 c.attrib['target'] = varname
265 d = tree.SubElement(b, 'manvolnum')
269 def _make_colophon(template, groups):
274 for pagelist in group.values():
275 pages |= set(pagelist)
277 para = template.find(".//para[@id='colophon']")
278 para.text = COLOPHON.format(count=count,
279 sections=len(groups),
282 def _make_page(template, directive_groups, formatting):
283 """Create an XML tree from directive_groups.
286 'class': {'variable': [('manpage', 'manvolume'), ...],
291 for name, directives in directive_groups.items():
292 _make_section(template, name, directives, formatting)
294 _make_colophon(template, directive_groups.values())
298 def make_page(*xml_files):
299 "Extract directives from xml_files and return XML index tree."
300 template = tree.fromstring(TEMPLATE)
301 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
302 directive_groups = {name:collections.defaultdict(list)
305 for page in xml_files:
307 _extract_directives(directive_groups, formatting, page)
309 raise ValueError("failed to process " + page)
311 return _make_page(template, directive_groups, formatting)
313 if __name__ == '__main__':
314 with open(sys.argv[1], 'wb') as f:
315 f.write(xml_print(make_page(*sys.argv[2:])))