1 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # This file is part of systemd.
5 # Copyright 2012-2013 Zbigniew Jędrzejewski-Szmek
7 # systemd is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
12 # systemd is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 from xml_helper import *
24 from copy import deepcopy
27 <refentry id="systemd.directives" conditional="HAVE_PYTHON">
30 <title>systemd.directives</title>
31 <productname>systemd</productname>
35 <contrib>Developer</contrib>
36 <firstname>Zbigniew</firstname>
37 <surname>Jędrzejewski-Szmek</surname>
38 <email>zbyszek@in.waw.pl</email>
44 <refentrytitle>systemd.directives</refentrytitle>
45 <manvolnum>7</manvolnum>
49 <refname>systemd.directives</refname>
50 <refpurpose>Index of configuration directives</refpurpose>
54 <title>Unit directives</title>
56 <para>Directives for configuring units, used in unit
59 <variablelist id='unit-directives' />
63 <title>Options on the kernel command line</title>
65 <para>Kernel boot options for configuring the behaviour of the
66 systemd process.</para>
68 <variablelist id='kernel-commandline-options' />
72 <title>Environment variables</title>
74 <para>Environment variables understood by the systemd
75 manager and other programs.</para>
77 <variablelist id='environment-variables' />
81 <title>UDEV directives</title>
83 <para>Directives for configuring systemd units through the
86 <variablelist id='udev-directives' />
90 <title>Journal fields</title>
92 <para>Fields in the journal events with a well known meaning.</para>
94 <variablelist id='journal-directives' />
98 <title>PAM configuration directives</title>
100 <para>Directives for configuring PAM behaviour.</para>
102 <variablelist id='pam-directives' />
106 <title>crypttab options</title>
108 <para>Options which influence mounted filesystems and
109 encrypted volumes.</para>
111 <variablelist id='crypttab-options' />
115 <title>System manager directives</title>
117 <para>Directives for configuring the behaviour of the
118 systemd process.</para>
120 <variablelist id='systemd-directives' />
124 <title>bootchart.conf directives</title>
126 <para>Directives for configuring the behaviour of the
127 systemd-bootchart process.</para>
129 <variablelist id='bootchart-directives' />
133 <title>command-line options</title>
135 <para>Command-line options accepted by programs in the
136 systemd suite.</para>
138 <variablelist id='options' />
142 <title>Miscellaneous options and directives</title>
144 <para>Other configuration elements which don't fit in
145 any of the above groups.</para>
147 <variablelist id='miscellaneous' />
151 <title>Files and directories</title>
153 <para>Paths and file names referred to in the
154 documentation.</para>
156 <variablelist id='filenames' />
160 <title>Colophon</title>
161 <para id='colophon' />
167 This index contains {count} entries in {sections} sections,
168 referring to {pages} individual manual pages.
171 def _extract_directives(directive_groups, formatting, page):
173 section = t.find('./refmeta/manvolnum').text
174 pagename = t.find('./refmeta/refentrytitle').text
176 storopt = directive_groups['options']
177 for variablelist in t.iterfind('.//variablelist'):
178 klass = variablelist.attrib.get('class')
179 storvar = directive_groups[klass or 'miscellaneous']
180 # <option>s go in OPTIONS, unless class is specified
181 for xpath, stor in (('./varlistentry/term/varname', storvar),
182 ('./varlistentry/term/option',
183 storvar if klass else storopt)):
184 for name in variablelist.iterfind(xpath):
185 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
186 stor[text].append((pagename, section))
187 if text not in formatting:
188 # use element as formatted display
189 if name.text[-1] in '= ':
194 formatting[text] = name
196 storfile = directive_groups['filenames']
197 for xpath, absolute_only in (('.//refsynopsisdiv//filename', False),
198 ('.//refsynopsisdiv//command', False),
199 ('.//filename', True)):
200 for name in t.iterfind(xpath):
201 if absolute_only and not (name.text and name.text.startswith('/')):
203 if name.attrib.get('noindex'):
207 if name.text.endswith('*'):
208 name.text = name.text[:-1]
209 if not name.text.startswith('.'):
210 text = name.text.partition(' ')[0]
211 if text != name.text:
214 if text.endswith('/'):
216 storfile[text].append((pagename, section))
217 if text not in formatting:
218 # use element as formatted display
219 formatting[text] = name
221 text = ' '.join(name.itertext())
222 storfile[text].append((pagename, section))
223 formatting[text] = name
225 def _make_section(template, name, directives, formatting):
226 varlist = template.find(".//*[@id='{}']".format(name))
227 for varname, manpages in sorted(directives.items()):
228 entry = tree.SubElement(varlist, 'varlistentry')
229 term = tree.SubElement(entry, 'term')
230 display = deepcopy(formatting[varname])
233 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
236 for manpage, manvolume in sorted(set(manpages)):
239 b = tree.SubElement(para, 'citerefentry')
240 c = tree.SubElement(b, 'refentrytitle')
242 d = tree.SubElement(b, 'manvolnum')
246 def _make_colophon(template, groups):
251 for pagelist in group.values():
252 pages |= set(pagelist)
254 para = template.find(".//para[@id='colophon']")
255 para.text = COLOPHON.format(count=count,
256 sections=len(groups),
259 def _make_page(template, directive_groups, formatting):
260 """Create an XML tree from directive_groups.
263 'class': {'variable': [('manpage', 'manvolume'), ...],
268 for name, directives in directive_groups.items():
269 _make_section(template, name, directives, formatting)
271 _make_colophon(template, directive_groups.values())
275 def make_page(*xml_files):
276 "Extract directives from xml_files and return XML index tree."
277 template = tree.fromstring(TEMPLATE)
278 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
279 directive_groups = {name:collections.defaultdict(list)
282 for page in xml_files:
284 _extract_directives(directive_groups, formatting, page)
286 raise ValueError("failed to process " + page)
288 return _make_page(template, directive_groups, formatting)
290 if __name__ == '__main__':
291 with open(sys.argv[1], 'wb') as f:
292 f.write(xml_print(make_page(*sys.argv[2:])))