2 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # SPDX-License-Identifier: LGPL-2.1+
8 from xml_helper import xml_parse, xml_print, tree
9 from copy import deepcopy
12 <refentry id="elogind.directives" conditional="HAVE_PYTHON">
15 <title>elogind.directives</title>
16 <productname>elogind</productname>
20 <contrib>Developer</contrib>
21 <firstname>Zbigniew</firstname>
22 <surname>Jędrzejewski-Szmek</surname>
23 <email>zbyszek@in.waw.pl</email>
29 <refentrytitle>elogind.directives</refentrytitle>
30 <manvolnum>7</manvolnum>
34 <refname>elogind.directives</refname>
35 <refpurpose>Index of configuration directives</refpurpose>
39 <title>Unit directives</title>
41 <para>Directives for configuring units, used in unit
44 <variablelist id='unit-directives' />
48 <title>Options on the kernel command line</title>
50 <para>Kernel boot options for configuring the behaviour of the
51 elogind process.</para>
53 <variablelist id='kernel-commandline-options' />
57 <title>Environment variables</title>
59 <para>Environment variables understood by the elogind
60 manager and other programs.</para>
62 <variablelist id='environment-variables' />
66 <title>UDEV directives</title>
68 <para>Directives for configuring elogind units through the
71 <variablelist id='udev-directives' />
75 <title>Network directives</title>
77 <para>Directives for configuring network links through the
78 net-setup-link udev builtin and networks through
79 elogind-networkd.</para>
81 <variablelist id='network-directives' />
85 <title>Journal fields</title>
87 <para>Fields in the journal events with a well known meaning.</para>
89 <variablelist id='journal-directives' />
93 <title>PAM configuration directives</title>
95 <para>Directives for configuring PAM behaviour.</para>
97 <variablelist id='pam-directives' />
101 <title><filename>/etc/crypttab</filename> and
102 <filename>/etc/fstab</filename> options</title>
104 <para>Options which influence mounted filesystems and
105 encrypted volumes.</para>
107 <variablelist id='fstab-options' />
111 <title>System manager directives</title>
113 <para>Directives for configuring the behaviour of the
114 elogind process.</para>
116 <variablelist id='elogind-directives' />
120 <title>command line options</title>
122 <para>Command-line options accepted by programs in the
123 elogind suite.</para>
125 <variablelist id='options' />
129 <title>Constants</title>
131 <para>Various constant used and/or defined by elogind.</para>
133 <variablelist id='constants' />
137 <title>Miscellaneous options and directives</title>
139 <para>Other configuration elements which don't fit in
140 any of the above groups.</para>
142 <variablelist id='miscellaneous' />
146 <title>Files and directories</title>
148 <para>Paths and file names referred to in the
149 documentation.</para>
151 <variablelist id='filenames' />
155 <title>Colophon</title>
156 <para id='colophon' />
162 This index contains {count} entries in {sections} sections,
163 referring to {pages} individual manual pages.
166 def _extract_directives(directive_groups, formatting, page):
168 section = t.find('./refmeta/manvolnum').text
169 pagename = t.find('./refmeta/refentrytitle').text
171 storopt = directive_groups['options']
172 for variablelist in t.iterfind('.//variablelist'):
173 klass = variablelist.attrib.get('class')
174 storvar = directive_groups[klass or 'miscellaneous']
175 # <option>s go in OPTIONS, unless class is specified
176 for xpath, stor in (('./varlistentry/term/varname', storvar),
177 ('./varlistentry/term/option',
178 storvar if klass else storopt)):
179 for name in variablelist.iterfind(xpath):
180 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
181 stor[text].append((pagename, section))
182 if text not in formatting:
183 # use element as formatted display
184 if name.text[-1] in '= ':
189 formatting[text] = name
191 storfile = directive_groups['filenames']
192 for xpath, absolute_only in (('.//refsynopsisdiv//filename', False),
193 ('.//refsynopsisdiv//command', False),
194 ('.//filename', True)):
195 for name in t.iterfind(xpath):
196 if absolute_only and not (name.text and name.text.startswith('/')):
198 if name.attrib.get('noindex'):
202 if name.text.endswith('*'):
203 name.text = name.text[:-1]
204 if not name.text.startswith('.'):
205 text = name.text.partition(' ')[0]
206 if text != name.text:
209 if text.endswith('/'):
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 storfile = directive_groups['constants']
221 for name in t.iterfind('.//constant'):
222 if name.attrib.get('noindex'):
225 if name.text.startswith('('): # a cast, strip it
226 name.text = name.text.partition(' ')[2]
227 storfile[name.text].append((pagename, section))
228 formatting[name.text] = name
230 def _make_section(template, name, directives, formatting):
231 varlist = template.find(".//*[@id='{}']".format(name))
232 for varname, manpages in sorted(directives.items()):
233 entry = tree.SubElement(varlist, 'varlistentry')
234 term = tree.SubElement(entry, 'term')
235 display = deepcopy(formatting[varname])
238 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
241 for manpage, manvolume in sorted(set(manpages)):
244 b = tree.SubElement(para, 'citerefentry')
245 c = tree.SubElement(b, 'refentrytitle')
247 c.attrib['target'] = varname
248 d = tree.SubElement(b, 'manvolnum')
252 def _make_colophon(template, groups):
257 for pagelist in group.values():
258 pages |= set(pagelist)
260 para = template.find(".//para[@id='colophon']")
261 para.text = COLOPHON.format(count=count,
262 sections=len(groups),
265 def _make_page(template, directive_groups, formatting):
266 """Create an XML tree from directive_groups.
269 'class': {'variable': [('manpage', 'manvolume'), ...],
274 for name, directives in directive_groups.items():
275 _make_section(template, name, directives, formatting)
277 _make_colophon(template, directive_groups.values())
281 def make_page(*xml_files):
282 "Extract directives from xml_files and return XML index tree."
283 template = tree.fromstring(TEMPLATE)
284 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
285 directive_groups = {name:collections.defaultdict(list)
288 for page in xml_files:
290 _extract_directives(directive_groups, formatting, page)
292 raise ValueError("failed to process " + page)
294 return _make_page(template, directive_groups, formatting)
296 if __name__ == '__main__':
297 with open(sys.argv[1], 'wb') as f:
298 f.write(xml_print(make_page(*sys.argv[2:])))