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