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