]>
Commit | Line | Data |
---|---|---|
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 |
20 | import sys |
21 | import collections | |
ccc9a4f9 | 22 | import re |
1a13e31d | 23 | from xml_helper import * |
827f70eb | 24 | from copy import deepcopy |
d9cfd694 ZJS |
25 | |
26 | TEMPLATE = '''\ | |
56ba3c78 | 27 | <refentry id="systemd.directives" conditional="HAVE_PYTHON"> |
d9cfd694 ZJS |
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> | |
9cc2c8b7 | 45 | <manvolnum>7</manvolnum> |
d9cfd694 ZJS |
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> | |
e1abd3ef | 61 | |
08177c85 ZJS |
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 | ||
ccc9a4f9 | 68 | <variablelist id='kernel-commandline-options' /> |
08177c85 ZJS |
69 | </refsect1> |
70 | ||
71 | <refsect1> | |
72 | <title>Environment variables</title> | |
73 | ||
ccc9a4f9 ZJS |
74 | <para>Environment variables understood by the systemd |
75 | manager and other programs.</para> | |
08177c85 ZJS |
76 | |
77 | <variablelist id='environment-variables' /> | |
78 | </refsect1> | |
79 | ||
e1abd3ef ZJS |
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> | |
f6c2e28b | 88 | |
1f06807c TG |
89 | <refsect1> |
90 | <title>Network directives</title> | |
91 | ||
92 | <para>Directives for configuring network links through the | |
93 | net-setup-link udev builtin.</para> | |
94 | ||
95 | <variablelist id='network-directives' /> | |
96 | </refsect1> | |
97 | ||
f6c2e28b | 98 | <refsect1> |
ccc9a4f9 | 99 | <title>Journal fields</title> |
f6c2e28b | 100 | |
ccc9a4f9 | 101 | <para>Fields in the journal events with a well known meaning.</para> |
f6c2e28b ZJS |
102 | |
103 | <variablelist id='journal-directives' /> | |
104 | </refsect1> | |
4a431c9a | 105 | |
ccc9a4f9 ZJS |
106 | <refsect1> |
107 | <title>PAM configuration directives</title> | |
108 | ||
109 | <para>Directives for configuring PAM behaviour.</para> | |
110 | ||
111 | <variablelist id='pam-directives' /> | |
112 | </refsect1> | |
113 | ||
114 | <refsect1> | |
115 | <title>crypttab options</title> | |
116 | ||
117 | <para>Options which influence mounted filesystems and | |
118 | encrypted volumes.</para> | |
119 | ||
120 | <variablelist id='crypttab-options' /> | |
121 | </refsect1> | |
122 | ||
123 | <refsect1> | |
124 | <title>System manager directives</title> | |
125 | ||
126 | <para>Directives for configuring the behaviour of the | |
127 | systemd process.</para> | |
128 | ||
129 | <variablelist id='systemd-directives' /> | |
130 | </refsect1> | |
131 | ||
4a431c9a ZJS |
132 | <refsect1> |
133 | <title>bootchart.conf directives</title> | |
134 | ||
135 | <para>Directives for configuring the behaviour of the | |
136 | systemd-bootchart process.</para> | |
137 | ||
138 | <variablelist id='bootchart-directives' /> | |
139 | </refsect1> | |
0acfdd61 | 140 | |
ccc9a4f9 ZJS |
141 | <refsect1> |
142 | <title>command-line options</title> | |
143 | ||
144 | <para>Command-line options accepted by programs in the | |
145 | systemd suite.</para> | |
146 | ||
147 | <variablelist id='options' /> | |
148 | </refsect1> | |
149 | ||
785a51eb ZJS |
150 | <refsect1> |
151 | <title>Constants</title> | |
152 | ||
153 | <para>Various constant used and/or defined by systemd.</para> | |
154 | ||
155 | <variablelist id='constants' /> | |
156 | </refsect1> | |
157 | ||
ccc9a4f9 ZJS |
158 | <refsect1> |
159 | <title>Miscellaneous options and directives</title> | |
160 | ||
161 | <para>Other configuration elements which don't fit in | |
162 | any of the above groups.</para> | |
163 | ||
164 | <variablelist id='miscellaneous' /> | |
165 | </refsect1> | |
166 | ||
a4e0b94d ZJS |
167 | <refsect1> |
168 | <title>Files and directories</title> | |
169 | ||
170 | <para>Paths and file names referred to in the | |
171 | documentation.</para> | |
172 | ||
173 | <variablelist id='filenames' /> | |
174 | </refsect1> | |
175 | ||
0acfdd61 ZJS |
176 | <refsect1> |
177 | <title>Colophon</title> | |
178 | <para id='colophon' /> | |
179 | </refsect1> | |
d9cfd694 ZJS |
180 | </refentry> |
181 | ''' | |
182 | ||
0acfdd61 ZJS |
183 | COLOPHON = '''\ |
184 | This index contains {count} entries in {sections} sections, | |
185 | referring to {pages} individual manual pages. | |
186 | ''' | |
187 | ||
d970bd6d | 188 | def _extract_directives(directive_groups, formatting, page): |
1a13e31d | 189 | t = xml_parse(page) |
d9cfd694 ZJS |
190 | section = t.find('./refmeta/manvolnum').text |
191 | pagename = t.find('./refmeta/refentrytitle').text | |
a4e0b94d ZJS |
192 | |
193 | storopt = directive_groups['options'] | |
d9cfd694 | 194 | for variablelist in t.iterfind('.//variablelist'): |
ccc9a4f9 ZJS |
195 | klass = variablelist.attrib.get('class') |
196 | storvar = directive_groups[klass or 'miscellaneous'] | |
ccc9a4f9 ZJS |
197 | # <option>s go in OPTIONS, unless class is specified |
198 | for xpath, stor in (('./varlistentry/term/varname', storvar), | |
199 | ('./varlistentry/term/option', | |
200 | storvar if klass else storopt)): | |
201 | for name in variablelist.iterfind(xpath): | |
202 | text = re.sub(r'([= ]).*', r'\1', name.text).rstrip() | |
203 | stor[text].append((pagename, section)) | |
d970bd6d ZJS |
204 | if text not in formatting: |
205 | # use element as formatted display | |
699ad6c0 ZJS |
206 | if name.text[-1] in '= ': |
207 | name.clear() | |
208 | else: | |
209 | name.tail = '' | |
d970bd6d ZJS |
210 | name.text = text |
211 | formatting[text] = name | |
d9cfd694 | 212 | |
a4e0b94d | 213 | storfile = directive_groups['filenames'] |
845c5324 ZJS |
214 | for xpath, absolute_only in (('.//refsynopsisdiv//filename', False), |
215 | ('.//refsynopsisdiv//command', False), | |
216 | ('.//filename', True)): | |
a4e0b94d | 217 | for name in t.iterfind(xpath): |
845c5324 ZJS |
218 | if absolute_only and not (name.text and name.text.startswith('/')): |
219 | continue | |
220 | if name.attrib.get('noindex'): | |
221 | continue | |
a4e0b94d ZJS |
222 | name.tail = '' |
223 | if name.text: | |
845c5324 ZJS |
224 | if name.text.endswith('*'): |
225 | name.text = name.text[:-1] | |
a4e0b94d ZJS |
226 | if not name.text.startswith('.'): |
227 | text = name.text.partition(' ')[0] | |
228 | if text != name.text: | |
229 | name.clear() | |
230 | name.text = text | |
845c5324 ZJS |
231 | if text.endswith('/'): |
232 | text = text[:-1] | |
a4e0b94d ZJS |
233 | storfile[text].append((pagename, section)) |
234 | if text not in formatting: | |
235 | # use element as formatted display | |
236 | formatting[text] = name | |
237 | else: | |
238 | text = ' '.join(name.itertext()) | |
239 | storfile[text].append((pagename, section)) | |
240 | formatting[text] = name | |
241 | ||
785a51eb ZJS |
242 | storfile = directive_groups['constants'] |
243 | for name in t.iterfind('.//constant'): | |
244 | if name.attrib.get('noindex'): | |
245 | continue | |
246 | name.tail = '' | |
247 | if name.text.startswith('('): # a cast, strip it | |
248 | name.text = name.text.partition(' ')[2] | |
249 | storfile[name.text].append((pagename, section)) | |
250 | formatting[name.text] = name | |
251 | ||
d970bd6d | 252 | def _make_section(template, name, directives, formatting): |
eeb019b5 | 253 | varlist = template.find(".//*[@id='{}']".format(name)) |
d9cfd694 ZJS |
254 | for varname, manpages in sorted(directives.items()): |
255 | entry = tree.SubElement(varlist, 'varlistentry') | |
d970bd6d | 256 | term = tree.SubElement(entry, 'term') |
827f70eb ZJS |
257 | display = deepcopy(formatting[varname]) |
258 | term.append(display) | |
d970bd6d | 259 | |
d9cfd694 ZJS |
260 | para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para') |
261 | ||
262 | b = None | |
ccc9a4f9 | 263 | for manpage, manvolume in sorted(set(manpages)): |
827f70eb ZJS |
264 | if b is not None: |
265 | b.tail = ', ' | |
266 | b = tree.SubElement(para, 'citerefentry') | |
267 | c = tree.SubElement(b, 'refentrytitle') | |
268 | c.text = manpage | |
269 | d = tree.SubElement(b, 'manvolnum') | |
270 | d.text = manvolume | |
d9cfd694 ZJS |
271 | entry.tail = '\n\n' |
272 | ||
0acfdd61 ZJS |
273 | def _make_colophon(template, groups): |
274 | count = 0 | |
275 | pages = set() | |
276 | for group in groups: | |
277 | count += len(group) | |
278 | for pagelist in group.values(): | |
279 | pages |= set(pagelist) | |
280 | ||
281 | para = template.find(".//para[@id='colophon']") | |
282 | para.text = COLOPHON.format(count=count, | |
283 | sections=len(groups), | |
284 | pages=len(pages)) | |
285 | ||
d970bd6d | 286 | def _make_page(template, directive_groups, formatting): |
d9cfd694 ZJS |
287 | """Create an XML tree from directive_groups. |
288 | ||
289 | directive_groups = { | |
290 | 'class': {'variable': [('manpage', 'manvolume'), ...], | |
291 | 'variable2': ...}, | |
292 | ... | |
293 | } | |
294 | """ | |
d9cfd694 | 295 | for name, directives in directive_groups.items(): |
827f70eb | 296 | _make_section(template, name, directives, formatting) |
d9cfd694 | 297 | |
0acfdd61 ZJS |
298 | _make_colophon(template, directive_groups.values()) |
299 | ||
eeb019b5 | 300 | return template |
d9cfd694 | 301 | |
ccc9a4f9 | 302 | def make_page(*xml_files): |
d9cfd694 | 303 | "Extract directives from xml_files and return XML index tree." |
eeb019b5 ZJS |
304 | template = tree.fromstring(TEMPLATE) |
305 | names = [vl.get('id') for vl in template.iterfind('.//variablelist')] | |
d9cfd694 | 306 | directive_groups = {name:collections.defaultdict(list) |
eeb019b5 | 307 | for name in names} |
d970bd6d | 308 | formatting = {} |
d9cfd694 | 309 | for page in xml_files: |
ccc9a4f9 | 310 | try: |
d970bd6d | 311 | _extract_directives(directive_groups, formatting, page) |
ccc9a4f9 ZJS |
312 | except Exception: |
313 | raise ValueError("failed to process " + page) | |
d9cfd694 | 314 | |
d970bd6d | 315 | return _make_page(template, directive_groups, formatting) |
d9cfd694 ZJS |
316 | |
317 | if __name__ == '__main__': | |
1a13e31d ZJS |
318 | with open(sys.argv[1], 'wb') as f: |
319 | f.write(xml_print(make_page(*sys.argv[2:]))) |