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
12 from xml_helper import xml_parse, xml_print, tree
13 from copy import deepcopy
16 <refentry id="elogind.directives" conditional="HAVE_PYTHON">
19 <title>elogind.directives</title>
20 <productname>elogind</productname>
24 <contrib>Developer</contrib>
25 <firstname>Zbigniew</firstname>
26 <surname>Jędrzejewski-Szmek</surname>
27 <email>zbyszek@in.waw.pl</email>
33 <refentrytitle>elogind.directives</refentrytitle>
34 <manvolnum>7</manvolnum>
38 <refname>elogind.directives</refname>
39 <refpurpose>Index of configuration directives</refpurpose>
43 <title>Unit directives</title>
45 <para>Directives for configuring units, used in unit
48 <variablelist id='unit-directives' />
52 <title>Options on the kernel command line</title>
54 <para>Kernel boot options for configuring the behaviour of the
55 elogind process.</para>
57 <variablelist id='kernel-commandline-options' />
61 <title>Environment variables</title>
63 <para>Environment variables understood by the elogind
64 manager and other programs.</para>
66 <variablelist id='environment-variables' />
70 <title>UDEV directives</title>
72 <para>Directives for configuring elogind units through the
75 <variablelist id='udev-directives' />
79 <title>Network directives</title>
81 <para>Directives for configuring network links through the
82 net-setup-link udev builtin and networks through
83 elogind-networkd.</para>
85 <variablelist id='network-directives' />
89 <title>Journal fields</title>
91 <para>Fields in the journal events with a well known meaning.</para>
93 <variablelist id='journal-directives' />
97 <title>PAM configuration directives</title>
99 <para>Directives for configuring PAM behaviour.</para>
101 <variablelist id='pam-directives' />
105 <title><filename>/etc/crypttab</filename> and
106 <filename>/etc/fstab</filename> options</title>
108 <para>Options which influence mounted filesystems and
109 encrypted volumes.</para>
111 <variablelist id='fstab-options' />
115 <title>System manager directives</title>
117 <para>Directives for configuring the behaviour of the
118 elogind process.</para>
120 <variablelist id='elogind-directives' />
124 <title>command line options</title>
126 <para>Command-line options accepted by programs in the
127 elogind suite.</para>
129 <variablelist id='options' />
133 <title>Constants</title>
135 <para>Various constant used and/or defined by elogind.</para>
137 <variablelist id='constants' />
141 <title>Miscellaneous options and directives</title>
143 <para>Other configuration elements which don't fit in
144 any of the above groups.</para>
146 <variablelist id='miscellaneous' />
150 <title>Files and directories</title>
152 <para>Paths and file names referred to in the
153 documentation.</para>
155 <variablelist id='filenames' />
159 <title>Colophon</title>
160 <para id='colophon' />
166 This index contains {count} entries in {sections} sections,
167 referring to {pages} individual manual pages.
170 def _extract_directives(directive_groups, formatting, page):
172 section = t.find('./refmeta/manvolnum').text
173 pagename = t.find('./refmeta/refentrytitle').text
175 storopt = directive_groups['options']
176 for variablelist in t.iterfind('.//variablelist'):
177 klass = variablelist.attrib.get('class')
178 storvar = directive_groups[klass or 'miscellaneous']
179 # <option>s go in OPTIONS, unless class is specified
180 for xpath, stor in (('./varlistentry/term/varname', storvar),
181 ('./varlistentry/term/option',
182 storvar if klass else storopt)):
183 for name in variablelist.iterfind(xpath):
184 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
185 stor[text].append((pagename, section))
186 if text not in formatting:
187 # use element as formatted display
188 if name.text[-1] in '= ':
193 formatting[text] = name
195 storfile = directive_groups['filenames']
196 for xpath, absolute_only in (('.//refsynopsisdiv//filename', False),
197 ('.//refsynopsisdiv//command', False),
198 ('.//filename', True)):
199 for name in t.iterfind(xpath):
200 if absolute_only and not (name.text and name.text.startswith('/')):
202 if name.attrib.get('noindex'):
206 if name.text.endswith('*'):
207 name.text = name.text[:-1]
208 if not name.text.startswith('.'):
209 text = name.text.partition(' ')[0]
210 if text != name.text:
213 if text.endswith('/'):
215 storfile[text].append((pagename, section))
216 if text not in formatting:
217 # use element as formatted display
218 formatting[text] = name
220 text = ' '.join(name.itertext())
221 storfile[text].append((pagename, section))
222 formatting[text] = name
224 storfile = directive_groups['constants']
225 for name in t.iterfind('.//constant'):
226 if name.attrib.get('noindex'):
229 if name.text.startswith('('): # a cast, strip it
230 name.text = name.text.partition(' ')[2]
231 storfile[name.text].append((pagename, section))
232 formatting[name.text] = name
234 def _make_section(template, name, directives, formatting):
235 varlist = template.find(".//*[@id='{}']".format(name))
236 for varname, manpages in sorted(directives.items()):
237 entry = tree.SubElement(varlist, 'varlistentry')
238 term = tree.SubElement(entry, 'term')
239 display = deepcopy(formatting[varname])
242 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
245 for manpage, manvolume in sorted(set(manpages)):
248 b = tree.SubElement(para, 'citerefentry')
249 c = tree.SubElement(b, 'refentrytitle')
251 c.attrib['target'] = varname
252 d = tree.SubElement(b, 'manvolnum')
256 def _make_colophon(template, groups):
261 for pagelist in group.values():
262 pages |= set(pagelist)
264 para = template.find(".//para[@id='colophon']")
265 para.text = COLOPHON.format(count=count,
266 sections=len(groups),
269 def _make_page(template, directive_groups, formatting):
270 """Create an XML tree from directive_groups.
273 'class': {'variable': [('manpage', 'manvolume'), ...],
278 for name, directives in directive_groups.items():
279 _make_section(template, name, directives, formatting)
281 _make_colophon(template, directive_groups.values())
285 def make_page(*xml_files):
286 "Extract directives from xml_files and return XML index tree."
287 template = tree.fromstring(TEMPLATE)
288 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
289 directive_groups = {name:collections.defaultdict(list)
292 for page in xml_files:
294 _extract_directives(directive_groups, formatting, page)
296 raise ValueError("failed to process " + page)
298 return _make_page(template, directive_groups, formatting)
300 if __name__ == '__main__':
301 with open(sys.argv[1], 'wb') as f:
302 f.write(xml_print(make_page(*sys.argv[2:])))