]> git.ipfire.org Git - thirdparty/systemd.git/blob - make-directive-index.py
machined: implement exit-on-idle
[thirdparty/systemd.git] / make-directive-index.py
1 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
2 #
3 # This file is part of systemd.
4 #
5 # Copyright 2012-2013 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
20 import sys
21 import collections
22 import re
23 from xml_helper import *
24 from copy import deepcopy
25
26 TEMPLATE = '''\
27 <refentry id="systemd.directives" conditional="HAVE_PYTHON">
28
29 <refentryinfo>
30 <title>systemd.directives</title>
31 <productname>systemd</productname>
32
33 <authorgroup>
34 <author>
35 <contrib>Developer</contrib>
36 <firstname>Zbigniew</firstname>
37 <surname>Jędrzejewski-Szmek</surname>
38 <email>zbyszek@in.waw.pl</email>
39 </author>
40 </authorgroup>
41 </refentryinfo>
42
43 <refmeta>
44 <refentrytitle>systemd.directives</refentrytitle>
45 <manvolnum>7</manvolnum>
46 </refmeta>
47
48 <refnamediv>
49 <refname>systemd.directives</refname>
50 <refpurpose>Index of configuration directives</refpurpose>
51 </refnamediv>
52
53 <refsect1>
54 <title>Unit directives</title>
55
56 <para>Directives for configuring units, used in unit
57 files.</para>
58
59 <variablelist id='unit-directives' />
60 </refsect1>
61
62 <refsect1>
63 <title>Options on the kernel command line</title>
64
65 <para>Kernel boot options for configuring the behaviour of the
66 systemd process.</para>
67
68 <variablelist id='kernel-commandline-options' />
69 </refsect1>
70
71 <refsect1>
72 <title>Environment variables</title>
73
74 <para>Environment variables understood by the systemd
75 manager and other programs.</para>
76
77 <variablelist id='environment-variables' />
78 </refsect1>
79
80 <refsect1>
81 <title>UDEV directives</title>
82
83 <para>Directives for configuring systemd units through the
84 udev database.</para>
85
86 <variablelist id='udev-directives' />
87 </refsect1>
88
89 <refsect1>
90 <title>Network directives</title>
91
92 <para>Directives for configuring network links through the
93 net-setup-link udev builtin and networks through
94 systemd-networkd.</para>
95
96 <variablelist id='network-directives' />
97 </refsect1>
98
99 <refsect1>
100 <title>Journal fields</title>
101
102 <para>Fields in the journal events with a well known meaning.</para>
103
104 <variablelist id='journal-directives' />
105 </refsect1>
106
107 <refsect1>
108 <title>PAM configuration directives</title>
109
110 <para>Directives for configuring PAM behaviour.</para>
111
112 <variablelist id='pam-directives' />
113 </refsect1>
114
115 <refsect1>
116 <title>crypttab options</title>
117
118 <para>Options which influence mounted filesystems and
119 encrypted volumes.</para>
120
121 <variablelist id='crypttab-options' />
122 </refsect1>
123
124 <refsect1>
125 <title>System manager directives</title>
126
127 <para>Directives for configuring the behaviour of the
128 systemd process.</para>
129
130 <variablelist id='systemd-directives' />
131 </refsect1>
132
133 <refsect1>
134 <title>bootchart.conf directives</title>
135
136 <para>Directives for configuring the behaviour of the
137 systemd-bootchart process.</para>
138
139 <variablelist id='bootchart-directives' />
140 </refsect1>
141
142 <refsect1>
143 <title>command-line options</title>
144
145 <para>Command-line options accepted by programs in the
146 systemd suite.</para>
147
148 <variablelist id='options' />
149 </refsect1>
150
151 <refsect1>
152 <title>Constants</title>
153
154 <para>Various constant used and/or defined by systemd.</para>
155
156 <variablelist id='constants' />
157 </refsect1>
158
159 <refsect1>
160 <title>Miscellaneous options and directives</title>
161
162 <para>Other configuration elements which don't fit in
163 any of the above groups.</para>
164
165 <variablelist id='miscellaneous' />
166 </refsect1>
167
168 <refsect1>
169 <title>Files and directories</title>
170
171 <para>Paths and file names referred to in the
172 documentation.</para>
173
174 <variablelist id='filenames' />
175 </refsect1>
176
177 <refsect1>
178 <title>Colophon</title>
179 <para id='colophon' />
180 </refsect1>
181 </refentry>
182 '''
183
184 COLOPHON = '''\
185 This index contains {count} entries in {sections} sections,
186 referring to {pages} individual manual pages.
187 '''
188
189 def _extract_directives(directive_groups, formatting, page):
190 t = xml_parse(page)
191 section = t.find('./refmeta/manvolnum').text
192 pagename = t.find('./refmeta/refentrytitle').text
193
194 storopt = directive_groups['options']
195 for variablelist in t.iterfind('.//variablelist'):
196 klass = variablelist.attrib.get('class')
197 storvar = directive_groups[klass or 'miscellaneous']
198 # <option>s go in OPTIONS, unless class is specified
199 for xpath, stor in (('./varlistentry/term/varname', storvar),
200 ('./varlistentry/term/option',
201 storvar if klass else storopt)):
202 for name in variablelist.iterfind(xpath):
203 text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
204 stor[text].append((pagename, section))
205 if text not in formatting:
206 # use element as formatted display
207 if name.text[-1] in '= ':
208 name.clear()
209 else:
210 name.tail = ''
211 name.text = text
212 formatting[text] = name
213
214 storfile = directive_groups['filenames']
215 for xpath, absolute_only in (('.//refsynopsisdiv//filename', False),
216 ('.//refsynopsisdiv//command', False),
217 ('.//filename', True)):
218 for name in t.iterfind(xpath):
219 if absolute_only and not (name.text and name.text.startswith('/')):
220 continue
221 if name.attrib.get('noindex'):
222 continue
223 name.tail = ''
224 if name.text:
225 if name.text.endswith('*'):
226 name.text = name.text[:-1]
227 if not name.text.startswith('.'):
228 text = name.text.partition(' ')[0]
229 if text != name.text:
230 name.clear()
231 name.text = text
232 if text.endswith('/'):
233 text = text[:-1]
234 storfile[text].append((pagename, section))
235 if text not in formatting:
236 # use element as formatted display
237 formatting[text] = name
238 else:
239 text = ' '.join(name.itertext())
240 storfile[text].append((pagename, section))
241 formatting[text] = name
242
243 storfile = directive_groups['constants']
244 for name in t.iterfind('.//constant'):
245 if name.attrib.get('noindex'):
246 continue
247 name.tail = ''
248 if name.text.startswith('('): # a cast, strip it
249 name.text = name.text.partition(' ')[2]
250 storfile[name.text].append((pagename, section))
251 formatting[name.text] = name
252
253 def _make_section(template, name, directives, formatting):
254 varlist = template.find(".//*[@id='{}']".format(name))
255 for varname, manpages in sorted(directives.items()):
256 entry = tree.SubElement(varlist, 'varlistentry')
257 term = tree.SubElement(entry, 'term')
258 display = deepcopy(formatting[varname])
259 term.append(display)
260
261 para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
262
263 b = None
264 for manpage, manvolume in sorted(set(manpages)):
265 if b is not None:
266 b.tail = ', '
267 b = tree.SubElement(para, 'citerefentry')
268 c = tree.SubElement(b, 'refentrytitle')
269 c.text = manpage
270 d = tree.SubElement(b, 'manvolnum')
271 d.text = manvolume
272 entry.tail = '\n\n'
273
274 def _make_colophon(template, groups):
275 count = 0
276 pages = set()
277 for group in groups:
278 count += len(group)
279 for pagelist in group.values():
280 pages |= set(pagelist)
281
282 para = template.find(".//para[@id='colophon']")
283 para.text = COLOPHON.format(count=count,
284 sections=len(groups),
285 pages=len(pages))
286
287 def _make_page(template, directive_groups, formatting):
288 """Create an XML tree from directive_groups.
289
290 directive_groups = {
291 'class': {'variable': [('manpage', 'manvolume'), ...],
292 'variable2': ...},
293 ...
294 }
295 """
296 for name, directives in directive_groups.items():
297 _make_section(template, name, directives, formatting)
298
299 _make_colophon(template, directive_groups.values())
300
301 return template
302
303 def make_page(*xml_files):
304 "Extract directives from xml_files and return XML index tree."
305 template = tree.fromstring(TEMPLATE)
306 names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
307 directive_groups = {name:collections.defaultdict(list)
308 for name in names}
309 formatting = {}
310 for page in xml_files:
311 try:
312 _extract_directives(directive_groups, formatting, page)
313 except Exception:
314 raise ValueError("failed to process " + page)
315
316 return _make_page(template, directive_groups, formatting)
317
318 if __name__ == '__main__':
319 with open(sys.argv[1], 'wb') as f:
320 f.write(xml_print(make_page(*sys.argv[2:])))