]>
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 | ||
141 | <refsect1> | |
142 | <title>Miscellaneous options and directives</title> | |
143 | ||
144 | <para>Other configuration elements which don't fit in | |
145 | any of the above groups.</para> | |
146 | ||
147 | <variablelist id='miscellaneous' /> | |
148 | </refsect1> | |
149 | ||
a4e0b94d ZJS |
150 | <refsect1> |
151 | <title>Files and directories</title> | |
152 | ||
153 | <para>Paths and file names referred to in the | |
154 | documentation.</para> | |
155 | ||
156 | <variablelist id='filenames' /> | |
157 | </refsect1> | |
158 | ||
0acfdd61 ZJS |
159 | <refsect1> |
160 | <title>Colophon</title> | |
161 | <para id='colophon' /> | |
162 | </refsect1> | |
d9cfd694 ZJS |
163 | </refentry> |
164 | ''' | |
165 | ||
0acfdd61 ZJS |
166 | COLOPHON = '''\ |
167 | This index contains {count} entries in {sections} sections, | |
168 | referring to {pages} individual manual pages. | |
169 | ''' | |
170 | ||
d970bd6d | 171 | def _extract_directives(directive_groups, formatting, page): |
1a13e31d | 172 | t = xml_parse(page) |
d9cfd694 ZJS |
173 | section = t.find('./refmeta/manvolnum').text |
174 | pagename = t.find('./refmeta/refentrytitle').text | |
a4e0b94d ZJS |
175 | |
176 | storopt = directive_groups['options'] | |
d9cfd694 | 177 | for variablelist in t.iterfind('.//variablelist'): |
ccc9a4f9 ZJS |
178 | klass = variablelist.attrib.get('class') |
179 | storvar = directive_groups[klass or 'miscellaneous'] | |
ccc9a4f9 ZJS |
180 | # <option>s go in OPTIONS, unless class is specified |
181 | for xpath, stor in (('./varlistentry/term/varname', storvar), | |
182 | ('./varlistentry/term/option', | |
183 | storvar if klass else storopt)): | |
184 | for name in variablelist.iterfind(xpath): | |
185 | text = re.sub(r'([= ]).*', r'\1', name.text).rstrip() | |
186 | stor[text].append((pagename, section)) | |
d970bd6d ZJS |
187 | if text not in formatting: |
188 | # use element as formatted display | |
699ad6c0 ZJS |
189 | if name.text[-1] in '= ': |
190 | name.clear() | |
191 | else: | |
192 | name.tail = '' | |
d970bd6d ZJS |
193 | name.text = text |
194 | formatting[text] = name | |
d9cfd694 | 195 | |
a4e0b94d | 196 | storfile = directive_groups['filenames'] |
845c5324 ZJS |
197 | for xpath, absolute_only in (('.//refsynopsisdiv//filename', False), |
198 | ('.//refsynopsisdiv//command', False), | |
199 | ('.//filename', True)): | |
a4e0b94d | 200 | for name in t.iterfind(xpath): |
845c5324 ZJS |
201 | if absolute_only and not (name.text and name.text.startswith('/')): |
202 | continue | |
203 | if name.attrib.get('noindex'): | |
204 | continue | |
a4e0b94d ZJS |
205 | name.tail = '' |
206 | if name.text: | |
845c5324 ZJS |
207 | if name.text.endswith('*'): |
208 | name.text = name.text[:-1] | |
a4e0b94d ZJS |
209 | if not name.text.startswith('.'): |
210 | text = name.text.partition(' ')[0] | |
211 | if text != name.text: | |
212 | name.clear() | |
213 | name.text = text | |
845c5324 ZJS |
214 | if text.endswith('/'): |
215 | text = text[:-1] | |
a4e0b94d ZJS |
216 | storfile[text].append((pagename, section)) |
217 | if text not in formatting: | |
218 | # use element as formatted display | |
219 | formatting[text] = name | |
220 | else: | |
221 | text = ' '.join(name.itertext()) | |
222 | storfile[text].append((pagename, section)) | |
223 | formatting[text] = name | |
224 | ||
d970bd6d | 225 | def _make_section(template, name, directives, formatting): |
eeb019b5 | 226 | varlist = template.find(".//*[@id='{}']".format(name)) |
d9cfd694 ZJS |
227 | for varname, manpages in sorted(directives.items()): |
228 | entry = tree.SubElement(varlist, 'varlistentry') | |
d970bd6d | 229 | term = tree.SubElement(entry, 'term') |
827f70eb ZJS |
230 | display = deepcopy(formatting[varname]) |
231 | term.append(display) | |
d970bd6d | 232 | |
d9cfd694 ZJS |
233 | para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para') |
234 | ||
235 | b = None | |
ccc9a4f9 | 236 | for manpage, manvolume in sorted(set(manpages)): |
827f70eb ZJS |
237 | if b is not None: |
238 | b.tail = ', ' | |
239 | b = tree.SubElement(para, 'citerefentry') | |
240 | c = tree.SubElement(b, 'refentrytitle') | |
241 | c.text = manpage | |
242 | d = tree.SubElement(b, 'manvolnum') | |
243 | d.text = manvolume | |
d9cfd694 ZJS |
244 | entry.tail = '\n\n' |
245 | ||
0acfdd61 ZJS |
246 | def _make_colophon(template, groups): |
247 | count = 0 | |
248 | pages = set() | |
249 | for group in groups: | |
250 | count += len(group) | |
251 | for pagelist in group.values(): | |
252 | pages |= set(pagelist) | |
253 | ||
254 | para = template.find(".//para[@id='colophon']") | |
255 | para.text = COLOPHON.format(count=count, | |
256 | sections=len(groups), | |
257 | pages=len(pages)) | |
258 | ||
d970bd6d | 259 | def _make_page(template, directive_groups, formatting): |
d9cfd694 ZJS |
260 | """Create an XML tree from directive_groups. |
261 | ||
262 | directive_groups = { | |
263 | 'class': {'variable': [('manpage', 'manvolume'), ...], | |
264 | 'variable2': ...}, | |
265 | ... | |
266 | } | |
267 | """ | |
d9cfd694 | 268 | for name, directives in directive_groups.items(): |
827f70eb | 269 | _make_section(template, name, directives, formatting) |
d9cfd694 | 270 | |
0acfdd61 ZJS |
271 | _make_colophon(template, directive_groups.values()) |
272 | ||
eeb019b5 | 273 | return template |
d9cfd694 | 274 | |
ccc9a4f9 | 275 | def make_page(*xml_files): |
d9cfd694 | 276 | "Extract directives from xml_files and return XML index tree." |
eeb019b5 ZJS |
277 | template = tree.fromstring(TEMPLATE) |
278 | names = [vl.get('id') for vl in template.iterfind('.//variablelist')] | |
d9cfd694 | 279 | directive_groups = {name:collections.defaultdict(list) |
eeb019b5 | 280 | for name in names} |
d970bd6d | 281 | formatting = {} |
d9cfd694 | 282 | for page in xml_files: |
ccc9a4f9 | 283 | try: |
d970bd6d | 284 | _extract_directives(directive_groups, formatting, page) |
ccc9a4f9 ZJS |
285 | except Exception: |
286 | raise ValueError("failed to process " + page) | |
d9cfd694 | 287 | |
d970bd6d | 288 | return _make_page(template, directive_groups, formatting) |
d9cfd694 ZJS |
289 | |
290 | if __name__ == '__main__': | |
1a13e31d ZJS |
291 | with open(sys.argv[1], 'wb') as f: |
292 | f.write(xml_print(make_page(*sys.argv[2:]))) |