]> git.ipfire.org Git - thirdparty/systemd.git/blame - make-directive-index.py
shared: conf-files - add root parameter
[thirdparty/systemd.git] / make-directive-index.py
CommitLineData
e7098b69
ZJS
1# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
2#
3# This file is part of systemd.
4#
ccc9a4f9 5# Copyright 2012-2013 Zbigniew Jędrzejewski-Szmek
e7098b69
ZJS
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
d9cfd694
ZJS
20import sys
21import collections
22import xml.etree.ElementTree as tree
ccc9a4f9 23import re
d9cfd694
ZJS
24
25TEMPLATE = '''\
56ba3c78 26<refentry id="systemd.directives" conditional="HAVE_PYTHON">
d9cfd694
ZJS
27
28 <refentryinfo>
29 <title>systemd.directives</title>
30 <productname>systemd</productname>
31
32 <authorgroup>
33 <author>
34 <contrib>Developer</contrib>
35 <firstname>Zbigniew</firstname>
36 <surname>Jędrzejewski-Szmek</surname>
37 <email>zbyszek@in.waw.pl</email>
38 </author>
39 </authorgroup>
40 </refentryinfo>
41
42 <refmeta>
43 <refentrytitle>systemd.directives</refentrytitle>
9cc2c8b7 44 <manvolnum>7</manvolnum>
d9cfd694
ZJS
45 </refmeta>
46
47 <refnamediv>
48 <refname>systemd.directives</refname>
49 <refpurpose>Index of configuration directives</refpurpose>
50 </refnamediv>
51
52 <refsect1>
53 <title>Unit directives</title>
54
55 <para>Directives for configuring units, used in unit
56 files.</para>
57
58 <variablelist id='unit-directives' />
59 </refsect1>
e1abd3ef 60
08177c85
ZJS
61 <refsect1>
62 <title>Options on the kernel command line</title>
63
64 <para>Kernel boot options for configuring the behaviour of the
65 systemd process.</para>
66
ccc9a4f9 67 <variablelist id='kernel-commandline-options' />
08177c85
ZJS
68 </refsect1>
69
70 <refsect1>
71 <title>Environment variables</title>
72
ccc9a4f9
ZJS
73 <para>Environment variables understood by the systemd
74 manager and other programs.</para>
08177c85
ZJS
75
76 <variablelist id='environment-variables' />
77 </refsect1>
78
e1abd3ef
ZJS
79 <refsect1>
80 <title>UDEV directives</title>
81
82 <para>Directives for configuring systemd units through the
83 udev database.</para>
84
85 <variablelist id='udev-directives' />
86 </refsect1>
f6c2e28b
ZJS
87
88 <refsect1>
ccc9a4f9 89 <title>Journal fields</title>
f6c2e28b 90
ccc9a4f9 91 <para>Fields in the journal events with a well known meaning.</para>
f6c2e28b
ZJS
92
93 <variablelist id='journal-directives' />
94 </refsect1>
4a431c9a 95
ccc9a4f9
ZJS
96 <refsect1>
97 <title>PAM configuration directives</title>
98
99 <para>Directives for configuring PAM behaviour.</para>
100
101 <variablelist id='pam-directives' />
102 </refsect1>
103
104 <refsect1>
105 <title>crypttab options</title>
106
107 <para>Options which influence mounted filesystems and
108 encrypted volumes.</para>
109
110 <variablelist id='crypttab-options' />
111 </refsect1>
112
113 <refsect1>
114 <title>System manager directives</title>
115
116 <para>Directives for configuring the behaviour of the
117 systemd process.</para>
118
119 <variablelist id='systemd-directives' />
120 </refsect1>
121
4a431c9a
ZJS
122 <refsect1>
123 <title>bootchart.conf directives</title>
124
125 <para>Directives for configuring the behaviour of the
126 systemd-bootchart process.</para>
127
128 <variablelist id='bootchart-directives' />
129 </refsect1>
0acfdd61 130
ccc9a4f9
ZJS
131 <refsect1>
132 <title>command-line options</title>
133
134 <para>Command-line options accepted by programs in the
135 systemd suite.</para>
136
137 <variablelist id='options' />
138 </refsect1>
139
140 <refsect1>
141 <title>Miscellaneous options and directives</title>
142
143 <para>Other configuration elements which don't fit in
144 any of the above groups.</para>
145
146 <variablelist id='miscellaneous' />
147 </refsect1>
148
0acfdd61
ZJS
149 <refsect1>
150 <title>Colophon</title>
151 <para id='colophon' />
152 </refsect1>
d9cfd694
ZJS
153</refentry>
154'''
155
0acfdd61
ZJS
156COLOPHON = '''\
157This index contains {count} entries in {sections} sections,
158referring to {pages} individual manual pages.
159'''
160
d970bd6d 161def _extract_directives(directive_groups, formatting, page):
d9cfd694
ZJS
162 t = tree.parse(page)
163 section = t.find('./refmeta/manvolnum').text
164 pagename = t.find('./refmeta/refentrytitle').text
165 for variablelist in t.iterfind('.//variablelist'):
ccc9a4f9
ZJS
166 klass = variablelist.attrib.get('class')
167 storvar = directive_groups[klass or 'miscellaneous']
168 storopt = directive_groups['options']
169 # <option>s go in OPTIONS, unless class is specified
170 for xpath, stor in (('./varlistentry/term/varname', storvar),
171 ('./varlistentry/term/option',
172 storvar if klass else storopt)):
173 for name in variablelist.iterfind(xpath):
174 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
175 stor[text].append((pagename, section))
d970bd6d
ZJS
176 if text not in formatting:
177 # use element as formatted display
178 name.tail = ''
179 name.text = text
180 formatting[text] = name
d9cfd694 181
d970bd6d 182def _make_section(template, name, directives, formatting):
eeb019b5 183 varlist = template.find(".//*[@id='{}']".format(name))
d9cfd694
ZJS
184 for varname, manpages in sorted(directives.items()):
185 entry = tree.SubElement(varlist, 'varlistentry')
d970bd6d
ZJS
186 term = tree.SubElement(entry, 'term')
187 term.append(formatting[varname])
188
d9cfd694
ZJS
189 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
190
191 b = None
ccc9a4f9 192 for manpage, manvolume in sorted(set(manpages)):
d9cfd694
ZJS
193 if b is not None:
194 b.tail = ', '
195 b = tree.SubElement(para, 'citerefentry')
196 c = tree.SubElement(b, 'refentrytitle')
197 c.text = manpage
198 d = tree.SubElement(b, 'manvolnum')
199 d.text = manvolume
200 entry.tail = '\n\n'
201
0acfdd61
ZJS
202def _make_colophon(template, groups):
203 count = 0
204 pages = set()
205 for group in groups:
206 count += len(group)
207 for pagelist in group.values():
208 pages |= set(pagelist)
209
210 para = template.find(".//para[@id='colophon']")
211 para.text = COLOPHON.format(count=count,
212 sections=len(groups),
213 pages=len(pages))
214
d970bd6d 215def _make_page(template, directive_groups, formatting):
d9cfd694
ZJS
216 """Create an XML tree from directive_groups.
217
218 directive_groups = {
219 'class': {'variable': [('manpage', 'manvolume'), ...],
220 'variable2': ...},
221 ...
222 }
223 """
d9cfd694 224 for name, directives in directive_groups.items():
d970bd6d 225 _make_section(template, name, directives, formatting)
d9cfd694 226
0acfdd61
ZJS
227 _make_colophon(template, directive_groups.values())
228
eeb019b5 229 return template
d9cfd694 230
ccc9a4f9 231def make_page(*xml_files):
d9cfd694 232 "Extract directives from xml_files and return XML index tree."
eeb019b5
ZJS
233 template = tree.fromstring(TEMPLATE)
234 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
d9cfd694 235 directive_groups = {name:collections.defaultdict(list)
eeb019b5 236 for name in names}
d970bd6d 237 formatting = {}
d9cfd694 238 for page in xml_files:
ccc9a4f9 239 try:
d970bd6d 240 _extract_directives(directive_groups, formatting, page)
ccc9a4f9
ZJS
241 except Exception:
242 raise ValueError("failed to process " + page)
d9cfd694 243
d970bd6d 244 return _make_page(template, directive_groups, formatting)
d9cfd694
ZJS
245
246if __name__ == '__main__':
ccc9a4f9 247 tree.dump(make_page(*sys.argv[1:]))