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>5</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>UDEV directives</title>
72 <para>Directives for configuring systemd units through the
75 <variablelist id='udev-directives' />
79 <title>Journal directives</title>
81 <para>Directives for configuring the behaviour of the
82 journald process.</para>
84 <variablelist id='journal-directives' />
88 <title>bootchart.conf directives</title>
90 <para>Directives for configuring the behaviour of the
91 systemd-bootchart process.</para>
93 <variablelist id='bootchart-directives' />
97 <title>Colophon</title>
98 <para id='colophon' />
104 This index contains {count} entries in {sections} sections,
105 referring to {pages} individual manual pages.
108 def _extract_directives(directive_groups, page):
110 section = t.find('./refmeta/manvolnum').text
111 pagename = t.find('./refmeta/refentrytitle').text
112 for variablelist in t.iterfind('.//variablelist'):
113 klass = variablelist.attrib.get('class') or 'unit-directives'
114 stor = directive_groups[klass]
115 for varname in variablelist.iterfind('./varlistentry/term/varname'):
116 text = ''.join(varname.text.partition('=')[:2])
117 stor[text].append((pagename, section))
119 def _make_section(template, name, directives):
120 varlist = template.find(".//*[@id='{}']".format(name))
121 for varname, manpages in sorted(directives.items()):
122 entry = tree.SubElement(varlist, 'varlistentry')
123 a = tree.SubElement(tree.SubElement(entry, 'term'), 'varname')
125 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
128 for manpage, manvolume in sorted(manpages):
131 b = tree.SubElement(para, 'citerefentry')
132 c = tree.SubElement(b, 'refentrytitle')
134 d = tree.SubElement(b, 'manvolnum')
138 def _make_colophon(template, groups):
143 for pagelist in group.values():
144 pages |= set(pagelist)
146 para = template.find(".//para[@id='colophon']")
147 para.text = COLOPHON.format(count=count,
148 sections=len(groups),
151 def _make_page(template, directive_groups):
152 """Create an XML tree from directive_groups.
155 'class': {'variable': [('manpage', 'manvolume'), ...],
160 for name, directives in directive_groups.items():
161 _make_section(template, name, directives)
163 _make_colophon(template, directive_groups.values())
167 def make_page(xml_files):
168 "Extract directives from xml_files and return XML index tree."
169 template = tree.fromstring(TEMPLATE)
170 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
171 directive_groups = {name:collections.defaultdict(list)
173 for page in xml_files:
174 _extract_directives(directive_groups, page)
176 return _make_page(template, directive_groups)
178 if __name__ == '__main__':
179 tree.dump(make_page(sys.argv[1:]))