blob: 3bf672e1a6b19704cdcdc956382d9836399d16e4 [file] [log] [blame]
Zbigniew Jędrzejewski-Szmeke7098b62012-11-13 18:39:18 +01001# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
2#
3# This file is part of systemd.
4#
5# Copyright 2012 Zbigniew Jędrzejewski-Szmek
6#
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.
11#
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.
16#
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/>.
19
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +020020import sys
21import collections
22import xml.etree.ElementTree as tree
23
24TEMPLATE = '''\
25<refentry id="systemd.directives">
26
27 <refentryinfo>
28 <title>systemd.directives</title>
29 <productname>systemd</productname>
30
31 <authorgroup>
32 <author>
33 <contrib>Developer</contrib>
34 <firstname>Zbigniew</firstname>
35 <surname>Jędrzejewski-Szmek</surname>
36 <email>zbyszek@in.waw.pl</email>
37 </author>
38 </authorgroup>
39 </refentryinfo>
40
41 <refmeta>
42 <refentrytitle>systemd.directives</refentrytitle>
43 <manvolnum>5</manvolnum>
44 </refmeta>
45
46 <refnamediv>
47 <refname>systemd.directives</refname>
48 <refpurpose>Index of configuration directives</refpurpose>
49 </refnamediv>
50
51 <refsect1>
52 <title>Unit directives</title>
53
54 <para>Directives for configuring units, used in unit
55 files.</para>
56
57 <variablelist id='unit-directives' />
58 </refsect1>
Zbigniew Jędrzejewski-Szmeke1abd3e2012-09-16 11:11:34 +020059
60 <refsect1>
Zbigniew Jędrzejewski-Szmekffafe912012-08-10 19:14:30 +020061 <title>System manager directives</title>
62
63 <para>Directives for configuring the behaviour of the
64 systemd process.</para>
65
66 <variablelist id='systemd-directives' />
67 </refsect1>
68
69 <refsect1>
Zbigniew Jędrzejewski-Szmeke1abd3e2012-09-16 11:11:34 +020070 <title>UDEV directives</title>
71
72 <para>Directives for configuring systemd units through the
73 udev database.</para>
74
75 <variablelist id='udev-directives' />
76 </refsect1>
Zbigniew Jędrzejewski-Szmekf6c2e282012-08-10 19:35:43 +020077
78 <refsect1>
79 <title>Journal directives</title>
80
81 <para>Directives for configuring the behaviour of the
82 journald process.</para>
83
84 <variablelist id='journal-directives' />
85 </refsect1>
Zbigniew Jędrzejewski-Szmek4a431c92013-01-14 20:18:36 -050086
87 <refsect1>
88 <title>bootchart.conf directives</title>
89
90 <para>Directives for configuring the behaviour of the
91 systemd-bootchart process.</para>
92
93 <variablelist id='bootchart-directives' />
94 </refsect1>
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -050095
96 <refsect1>
97 <title>Colophon</title>
98 <para id='colophon' />
99 </refsect1>
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200100</refentry>
101'''
102
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500103COLOPHON = '''\
104This index contains {count} entries in {sections} sections,
105referring to {pages} individual manual pages.
106'''
107
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200108def _extract_directives(directive_groups, page):
109 t = tree.parse(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))
118
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500119def _make_section(template, name, directives):
120 varlist = template.find(".//*[@id='{}']".format(name))
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200121 for varname, manpages in sorted(directives.items()):
122 entry = tree.SubElement(varlist, 'varlistentry')
123 a = tree.SubElement(tree.SubElement(entry, 'term'), 'varname')
124 a.text = varname
125 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
126
127 b = None
128 for manpage, manvolume in sorted(manpages):
129 if b is not None:
130 b.tail = ', '
131 b = tree.SubElement(para, 'citerefentry')
132 c = tree.SubElement(b, 'refentrytitle')
133 c.text = manpage
134 d = tree.SubElement(b, 'manvolnum')
135 d.text = manvolume
136 entry.tail = '\n\n'
137
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500138def _make_colophon(template, groups):
139 count = 0
140 pages = set()
141 for group in groups:
142 count += len(group)
143 for pagelist in group.values():
144 pages |= set(pagelist)
145
146 para = template.find(".//para[@id='colophon']")
147 para.text = COLOPHON.format(count=count,
148 sections=len(groups),
149 pages=len(pages))
150
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500151def _make_page(template, directive_groups):
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200152 """Create an XML tree from directive_groups.
153
154 directive_groups = {
155 'class': {'variable': [('manpage', 'manvolume'), ...],
156 'variable2': ...},
157 ...
158 }
159 """
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200160 for name, directives in directive_groups.items():
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500161 _make_section(template, name, directives)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200162
Zbigniew Jędrzejewski-Szmek0acfdd62013-01-14 21:34:19 -0500163 _make_colophon(template, directive_groups.values())
164
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500165 return template
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200166
167def make_page(xml_files):
168 "Extract directives from xml_files and return XML index tree."
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500169 template = tree.fromstring(TEMPLATE)
170 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200171 directive_groups = {name:collections.defaultdict(list)
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500172 for name in names}
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200173 for page in xml_files:
174 _extract_directives(directive_groups, page)
175
Zbigniew Jędrzejewski-Szmekeeb019b2013-01-14 21:02:49 -0500176 return _make_page(template, directive_groups)
Zbigniew Jędrzejewski-Szmekd9cfd692012-08-09 18:08:14 +0200177
178if __name__ == '__main__':
179 tree.dump(make_page(sys.argv[1:]))