2 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # SPDX-License-Identifier: LGPL-2.1+
5 # Copyright © 2012-2013 Zbigniew Jędrzejewski-Szmek
10 from xml_helper import xml_parse, xml_print, tree
11 from copy import deepcopy
14 <refentry id="elogind.directives" conditional="HAVE_PYTHON">
17 <title>elogind.directives</title>
18 <productname>elogind</productname>
22 <refentrytitle>elogind.directives</refentrytitle>
23 <manvolnum>7</manvolnum>
27 <refname>elogind.directives</refname>
28 <refpurpose>Index of configuration directives</refpurpose>
32 <title>Unit directives</title>
34 <para>Directives for configuring units, used in unit
37 <variablelist id='unit-directives' />
41 <title>Options on the kernel command line</title>
43 <para>Kernel boot options for configuring the behaviour of the
44 elogind process.</para>
46 <variablelist id='kernel-commandline-options' />
50 <title>Environment variables</title>
52 <para>Environment variables understood by the elogind
53 manager and other programs.</para>
55 <variablelist id='environment-variables' />
59 <title>UDEV directives</title>
61 <para>Directives for configuring elogind units through the
64 <variablelist id='udev-directives' />
68 <title>Network directives</title>
70 <para>Directives for configuring network links through the
71 net-setup-link udev builtin and networks through
72 elogind-networkd.</para>
74 <variablelist id='network-directives' />
78 <title>Journal fields</title>
80 <para>Fields in the journal events with a well known meaning.</para>
82 <variablelist id='journal-directives' />
86 <title>PAM configuration directives</title>
88 <para>Directives for configuring PAM behaviour.</para>
90 <variablelist id='pam-directives' />
94 <title><filename>/etc/crypttab</filename> and
95 <filename>/etc/fstab</filename> options</title>
97 <para>Options which influence mounted filesystems and
98 encrypted volumes.</para>
100 <variablelist id='fstab-options' />
104 <title>System manager directives</title>
106 <para>Directives for configuring the behaviour of the
107 elogind process.</para>
109 <variablelist id='elogind-directives' />
113 <title>command line options</title>
115 <para>Command-line options accepted by programs in the
116 elogind suite.</para>
118 <variablelist id='options' />
122 <title>Constants</title>
124 <para>Various constant used and/or defined by elogind.</para>
126 <variablelist id='constants' />
130 <title>Miscellaneous options and directives</title>
132 <para>Other configuration elements which don't fit in
133 any of the above groups.</para>
135 <variablelist id='miscellaneous' />
139 <title>Files and directories</title>
141 <para>Paths and file names referred to in the
142 documentation.</para>
144 <variablelist id='filenames' />
148 <title>Colophon</title>
149 <para id='colophon' />
155 This index contains {count} entries in {sections} sections,
156 referring to {pages} individual manual pages.
159 def _extract_directives(directive_groups, formatting, page):
161 section = t.find('./refmeta/manvolnum').text
162 pagename = t.find('./refmeta/refentrytitle').text
164 storopt = directive_groups['options']
165 for variablelist in t.iterfind('.//variablelist'):
166 klass = variablelist.attrib.get('class')
167 storvar = directive_groups[klass or 'miscellaneous']
168 # <option>s go in OPTIONS, unless class is specified
169 for xpath, stor in (('./varlistentry/term/varname', storvar),
170 ('./varlistentry/term/option',
171 storvar if klass else storopt)):
172 for name in variablelist.iterfind(xpath):
173 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
174 stor[text].append((pagename, section))
175 if text not in formatting:
176 # use element as formatted display
177 if name.text[-1] in '= ':
182 formatting[text] = name
184 storfile = directive_groups['filenames']
185 for xpath, absolute_only in (('.//refsynopsisdiv//filename', False),
186 ('.//refsynopsisdiv//command', False),
187 ('.//filename', True)):
188 for name in t.iterfind(xpath):
189 if absolute_only and not (name.text and name.text.startswith('/')):
191 if name.attrib.get('noindex'):
195 if name.text.endswith('*'):
196 name.text = name.text[:-1]
197 if not name.text.startswith('.'):
198 text = name.text.partition(' ')[0]
199 if text != name.text:
202 if text.endswith('/'):
204 storfile[text].append((pagename, section))
205 if text not in formatting:
206 # use element as formatted display
207 formatting[text] = name
209 text = ' '.join(name.itertext())
210 storfile[text].append((pagename, section))
211 formatting[text] = name
213 storfile = directive_groups['constants']
214 for name in t.iterfind('.//constant'):
215 if name.attrib.get('noindex'):
218 if name.text.startswith('('): # a cast, strip it
219 name.text = name.text.partition(' ')[2]
220 storfile[name.text].append((pagename, section))
221 formatting[name.text] = name
223 def _make_section(template, name, directives, formatting):
224 varlist = template.find(".//*[@id='{}']".format(name))
225 for varname, manpages in sorted(directives.items()):
226 entry = tree.SubElement(varlist, 'varlistentry')
227 term = tree.SubElement(entry, 'term')
228 display = deepcopy(formatting[varname])
231 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
234 for manpage, manvolume in sorted(set(manpages)):
237 b = tree.SubElement(para, 'citerefentry')
238 c = tree.SubElement(b, 'refentrytitle')
240 c.attrib['target'] = varname
241 d = tree.SubElement(b, 'manvolnum')
245 def _make_colophon(template, groups):
250 for pagelist in group.values():
251 pages |= set(pagelist)
253 para = template.find(".//para[@id='colophon']")
254 para.text = COLOPHON.format(count=count,
255 sections=len(groups),
258 def _make_page(template, directive_groups, formatting):
259 """Create an XML tree from directive_groups.
262 'class': {'variable': [('manpage', 'manvolume'), ...],
267 for name, directives in directive_groups.items():
268 _make_section(template, name, directives, formatting)
270 _make_colophon(template, directive_groups.values())
274 def make_page(*xml_files):
275 "Extract directives from xml_files and return XML index tree."
276 template = tree.fromstring(TEMPLATE)
277 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
278 directive_groups = {name:collections.defaultdict(list)
281 for page in xml_files:
283 _extract_directives(directive_groups, formatting, page)
285 raise ValueError("failed to process " + page)
287 return _make_page(template, directive_groups, formatting)
289 if __name__ == '__main__':
290 with open(sys.argv[1], 'wb') as f:
291 f.write(xml_print(make_page(*sys.argv[2:])))