1 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # This file is part of systemd.
5 # Copyright 2012 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/>.
22 import xml.etree.ElementTree as tree
25 <refentry id="systemd.directives">
28 <title>systemd.directives</title>
29 <productname>systemd</productname>
33 <contrib>Developer</contrib>
34 <firstname>Zbigniew</firstname>
35 <surname>Jędrzejewski-Szmek</surname>
36 <email>zbyszek@in.waw.pl</email>
42 <refentrytitle>systemd.directives</refentrytitle>
43 <manvolnum>7</manvolnum>
47 <refname>systemd.directives</refname>
48 <refpurpose>Index of configuration directives</refpurpose>
52 <title>Unit directives</title>
54 <para>Directives for configuring units, used in unit
57 <variablelist id='unit-directives' />
61 <title>System manager directives</title>
63 <para>Directives for configuring the behaviour of the
64 systemd process.</para>
66 <variablelist id='systemd-directives' />
70 <title>Options on the kernel command line</title>
72 <para>Kernel boot options for configuring the behaviour of the
73 systemd process.</para>
75 <variablelist id='kernel-commandline-directives' />
79 <title>Environment variables</title>
81 <para>Environment variables understood by the systemd process.</para>
83 <variablelist id='environment-variables' />
87 <title>UDEV directives</title>
89 <para>Directives for configuring systemd units through the
92 <variablelist id='udev-directives' />
96 <title>Journal directives</title>
98 <para>Directives for configuring the behaviour of the
99 journald process.</para>
101 <variablelist id='journal-directives' />
105 <title>bootchart.conf directives</title>
107 <para>Directives for configuring the behaviour of the
108 systemd-bootchart process.</para>
110 <variablelist id='bootchart-directives' />
114 <title>Colophon</title>
115 <para id='colophon' />
121 This index contains {count} entries in {sections} sections,
122 referring to {pages} individual manual pages.
125 def _extract_directives(directive_groups, page):
127 section = t.find('./refmeta/manvolnum').text
128 pagename = t.find('./refmeta/refentrytitle').text
129 for variablelist in t.iterfind('.//variablelist'):
130 klass = variablelist.attrib.get('class') or 'unit-directives'
131 stor = directive_groups[klass]
132 for varname in variablelist.iterfind('./varlistentry/term/varname'):
133 text = ''.join(varname.text.partition('=')[:2])
134 stor[text].append((pagename, section))
136 def _make_section(template, name, directives):
137 varlist = template.find(".//*[@id='{}']".format(name))
138 for varname, manpages in sorted(directives.items()):
139 entry = tree.SubElement(varlist, 'varlistentry')
140 a = tree.SubElement(tree.SubElement(entry, 'term'), 'varname')
142 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
145 for manpage, manvolume in sorted(manpages):
148 b = tree.SubElement(para, 'citerefentry')
149 c = tree.SubElement(b, 'refentrytitle')
151 d = tree.SubElement(b, 'manvolnum')
155 def _make_colophon(template, groups):
160 for pagelist in group.values():
161 pages |= set(pagelist)
163 para = template.find(".//para[@id='colophon']")
164 para.text = COLOPHON.format(count=count,
165 sections=len(groups),
168 def _make_page(template, directive_groups):
169 """Create an XML tree from directive_groups.
172 'class': {'variable': [('manpage', 'manvolume'), ...],
177 for name, directives in directive_groups.items():
178 _make_section(template, name, directives)
180 _make_colophon(template, directive_groups.values())
184 def make_page(xml_files):
185 "Extract directives from xml_files and return XML index tree."
186 template = tree.fromstring(TEMPLATE)
187 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
188 directive_groups = {name:collections.defaultdict(list)
190 for page in xml_files:
191 _extract_directives(directive_groups, page)
193 return _make_page(template, directive_groups)
195 if __name__ == '__main__':
196 tree.dump(make_page(sys.argv[1:]))