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