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 <contrib>Developer</contrib>
23 <firstname>Zbigniew</firstname>
24 <surname>Jędrzejewski-Szmek</surname>
25 <email>zbyszek@in.waw.pl</email>
31 <refentrytitle>elogind.directives</refentrytitle>
32 <manvolnum>7</manvolnum>
36 <refname>elogind.directives</refname>
37 <refpurpose>Index of configuration directives</refpurpose>
41 <title>Unit directives</title>
43 <para>Directives for configuring units, used in unit
46 <variablelist id='unit-directives' />
50 <title>Options on the kernel command line</title>
52 <para>Kernel boot options for configuring the behaviour of the
53 elogind process.</para>
55 <variablelist id='kernel-commandline-options' />
59 <title>Environment variables</title>
61 <para>Environment variables understood by the elogind
62 manager and other programs.</para>
64 <variablelist id='environment-variables' />
68 <title>UDEV directives</title>
70 <para>Directives for configuring elogind units through the
73 <variablelist id='udev-directives' />
77 <title>Network directives</title>
79 <para>Directives for configuring network links through the
80 net-setup-link udev builtin and networks through
81 elogind-networkd.</para>
83 <variablelist id='network-directives' />
87 <title>Journal fields</title>
89 <para>Fields in the journal events with a well known meaning.</para>
91 <variablelist id='journal-directives' />
95 <title>PAM configuration directives</title>
97 <para>Directives for configuring PAM behaviour.</para>
99 <variablelist id='pam-directives' />
103 <title><filename>/etc/crypttab</filename> and
104 <filename>/etc/fstab</filename> options</title>
106 <para>Options which influence mounted filesystems and
107 encrypted volumes.</para>
109 <variablelist id='fstab-options' />
113 <title>System manager directives</title>
115 <para>Directives for configuring the behaviour of the
116 elogind process.</para>
118 <variablelist id='elogind-directives' />
122 <title>command line options</title>
124 <para>Command-line options accepted by programs in the
125 elogind suite.</para>
127 <variablelist id='options' />
131 <title>Constants</title>
133 <para>Various constant used and/or defined by elogind.</para>
135 <variablelist id='constants' />
139 <title>Miscellaneous options and directives</title>
141 <para>Other configuration elements which don't fit in
142 any of the above groups.</para>
144 <variablelist id='miscellaneous' />
148 <title>Files and directories</title>
150 <para>Paths and file names referred to in the
151 documentation.</para>
153 <variablelist id='filenames' />
157 <title>Colophon</title>
158 <para id='colophon' />
164 This index contains {count} entries in {sections} sections,
165 referring to {pages} individual manual pages.
168 def _extract_directives(directive_groups, formatting, page):
170 section = t.find('./refmeta/manvolnum').text
171 pagename = t.find('./refmeta/refentrytitle').text
173 storopt = directive_groups['options']
174 for variablelist in t.iterfind('.//variablelist'):
175 klass = variablelist.attrib.get('class')
176 storvar = directive_groups[klass or 'miscellaneous']
177 # <option>s go in OPTIONS, unless class is specified
178 for xpath, stor in (('./varlistentry/term/varname', storvar),
179 ('./varlistentry/term/option',
180 storvar if klass else storopt)):
181 for name in variablelist.iterfind(xpath):
182 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
183 stor[text].append((pagename, section))
184 if text not in formatting:
185 # use element as formatted display
186 if name.text[-1] in '= ':
191 formatting[text] = name
193 storfile = directive_groups['filenames']
194 for xpath, absolute_only in (('.//refsynopsisdiv//filename', False),
195 ('.//refsynopsisdiv//command', False),
196 ('.//filename', True)):
197 for name in t.iterfind(xpath):
198 if absolute_only and not (name.text and name.text.startswith('/')):
200 if name.attrib.get('noindex'):
204 if name.text.endswith('*'):
205 name.text = name.text[:-1]
206 if not name.text.startswith('.'):
207 text = name.text.partition(' ')[0]
208 if text != name.text:
211 if text.endswith('/'):
213 storfile[text].append((pagename, section))
214 if text not in formatting:
215 # use element as formatted display
216 formatting[text] = name
218 text = ' '.join(name.itertext())
219 storfile[text].append((pagename, section))
220 formatting[text] = name
222 storfile = directive_groups['constants']
223 for name in t.iterfind('.//constant'):
224 if name.attrib.get('noindex'):
227 if name.text.startswith('('): # a cast, strip it
228 name.text = name.text.partition(' ')[2]
229 storfile[name.text].append((pagename, section))
230 formatting[name.text] = name
232 def _make_section(template, name, directives, formatting):
233 varlist = template.find(".//*[@id='{}']".format(name))
234 for varname, manpages in sorted(directives.items()):
235 entry = tree.SubElement(varlist, 'varlistentry')
236 term = tree.SubElement(entry, 'term')
237 display = deepcopy(formatting[varname])
240 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
243 for manpage, manvolume in sorted(set(manpages)):
246 b = tree.SubElement(para, 'citerefentry')
247 c = tree.SubElement(b, 'refentrytitle')
249 c.attrib['target'] = varname
250 d = tree.SubElement(b, 'manvolnum')
254 def _make_colophon(template, groups):
259 for pagelist in group.values():
260 pages |= set(pagelist)
262 para = template.find(".//para[@id='colophon']")
263 para.text = COLOPHON.format(count=count,
264 sections=len(groups),
267 def _make_page(template, directive_groups, formatting):
268 """Create an XML tree from directive_groups.
271 'class': {'variable': [('manpage', 'manvolume'), ...],
276 for name, directives in directive_groups.items():
277 _make_section(template, name, directives, formatting)
279 _make_colophon(template, directive_groups.values())
283 def make_page(*xml_files):
284 "Extract directives from xml_files and return XML index tree."
285 template = tree.fromstring(TEMPLATE)
286 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
287 directive_groups = {name:collections.defaultdict(list)
290 for page in xml_files:
292 _extract_directives(directive_groups, formatting, page)
294 raise ValueError("failed to process " + page)
296 return _make_page(template, directive_groups, formatting)
298 if __name__ == '__main__':
299 with open(sys.argv[1], 'wb') as f:
300 f.write(xml_print(make_page(*sys.argv[2:])))