Jörg Thalheim | 3e67e5c | 2017-05-01 02:26:56 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Zbigniew Jędrzejewski-Szmek | 35df744 | 2017-11-18 17:32:46 +0100 | [diff] [blame] | 2 | # SPDX-License-Identifier: LGPL-2.1+ |
Zbigniew Jędrzejewski-Szmek | e7098b6 | 2012-11-13 18:39:18 +0100 | [diff] [blame] | 3 | |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 4 | import sys |
| 5 | import collections |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 6 | import re |
Zbigniew Jędrzejewski-Szmek | 1c6c3ef | 2017-07-02 20:26:32 -0400 | [diff] [blame] | 7 | from xml_helper import xml_parse, xml_print, tree |
Zbigniew Jędrzejewski-Szmek | 827f70e | 2013-05-29 22:31:20 -0400 | [diff] [blame] | 8 | from copy import deepcopy |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 9 | |
| 10 | TEMPLATE = '''\ |
Zbigniew Jędrzejewski-Szmek | 56ba3c7 | 2013-02-02 22:47:47 -0500 | [diff] [blame] | 11 | <refentry id="systemd.directives" conditional="HAVE_PYTHON"> |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 12 | |
| 13 | <refentryinfo> |
| 14 | <title>systemd.directives</title> |
| 15 | <productname>systemd</productname> |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 16 | </refentryinfo> |
| 17 | |
| 18 | <refmeta> |
| 19 | <refentrytitle>systemd.directives</refentrytitle> |
Zbigniew Jędrzejewski-Szmek | 9cc2c8b | 2013-01-14 22:08:33 -0500 | [diff] [blame] | 20 | <manvolnum>7</manvolnum> |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 21 | </refmeta> |
| 22 | |
| 23 | <refnamediv> |
| 24 | <refname>systemd.directives</refname> |
| 25 | <refpurpose>Index of configuration directives</refpurpose> |
| 26 | </refnamediv> |
| 27 | |
| 28 | <refsect1> |
| 29 | <title>Unit directives</title> |
| 30 | |
| 31 | <para>Directives for configuring units, used in unit |
| 32 | files.</para> |
| 33 | |
| 34 | <variablelist id='unit-directives' /> |
| 35 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | e1abd3e | 2012-09-16 11:11:34 +0200 | [diff] [blame] | 36 | |
| 37 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | 08177c8 | 2013-01-14 21:58:22 -0500 | [diff] [blame] | 38 | <title>Options on the kernel command line</title> |
| 39 | |
| 40 | <para>Kernel boot options for configuring the behaviour of the |
| 41 | systemd process.</para> |
| 42 | |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 43 | <variablelist id='kernel-commandline-options' /> |
Zbigniew Jędrzejewski-Szmek | 08177c8 | 2013-01-14 21:58:22 -0500 | [diff] [blame] | 44 | </refsect1> |
| 45 | |
| 46 | <refsect1> |
| 47 | <title>Environment variables</title> |
| 48 | |
Zbigniew Jędrzejewski-Szmek | 833fc98 | 2019-02-13 10:36:26 +0100 | [diff] [blame] | 49 | <para>Environment variables understood by the systemd manager |
| 50 | and other programs and environment variable-compatible settings.</para> |
Zbigniew Jędrzejewski-Szmek | 08177c8 | 2013-01-14 21:58:22 -0500 | [diff] [blame] | 51 | |
| 52 | <variablelist id='environment-variables' /> |
| 53 | </refsect1> |
| 54 | |
| 55 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | bc61c2b | 2019-02-13 11:09:02 +0100 | [diff] [blame] | 56 | <title>EFI variables</title> |
| 57 | |
| 58 | <para>EFI variables understood by |
| 59 | <citerefentry><refentrytitle>systemd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry> |
| 60 | and other programs.</para> |
| 61 | |
| 62 | <variablelist id='efi-variables' /> |
| 63 | </refsect1> |
| 64 | |
| 65 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | e1abd3e | 2012-09-16 11:11:34 +0200 | [diff] [blame] | 66 | <title>UDEV directives</title> |
| 67 | |
| 68 | <para>Directives for configuring systemd units through the |
| 69 | udev database.</para> |
| 70 | |
| 71 | <variablelist id='udev-directives' /> |
| 72 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | f6c2e28 | 2012-08-10 19:35:43 +0200 | [diff] [blame] | 73 | |
| 74 | <refsect1> |
Tom Gundersen | 1f06807 | 2013-11-10 19:33:18 +0100 | [diff] [blame] | 75 | <title>Network directives</title> |
| 76 | |
| 77 | <para>Directives for configuring network links through the |
Tom Gundersen | 46b0925 | 2013-11-10 20:52:53 +0100 | [diff] [blame] | 78 | net-setup-link udev builtin and networks through |
| 79 | systemd-networkd.</para> |
Tom Gundersen | 1f06807 | 2013-11-10 19:33:18 +0100 | [diff] [blame] | 80 | |
| 81 | <variablelist id='network-directives' /> |
| 82 | </refsect1> |
| 83 | |
| 84 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 85 | <title>Journal fields</title> |
Zbigniew Jędrzejewski-Szmek | f6c2e28 | 2012-08-10 19:35:43 +0200 | [diff] [blame] | 86 | |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 87 | <para>Fields in the journal events with a well known meaning.</para> |
Zbigniew Jędrzejewski-Szmek | f6c2e28 | 2012-08-10 19:35:43 +0200 | [diff] [blame] | 88 | |
| 89 | <variablelist id='journal-directives' /> |
| 90 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | 4a431c9 | 2013-01-14 20:18:36 -0500 | [diff] [blame] | 91 | |
| 92 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 93 | <title>PAM configuration directives</title> |
| 94 | |
| 95 | <para>Directives for configuring PAM behaviour.</para> |
| 96 | |
| 97 | <variablelist id='pam-directives' /> |
| 98 | </refsect1> |
| 99 | |
| 100 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | 63b03c0 | 2014-06-30 09:27:16 -0400 | [diff] [blame] | 101 | <title><filename>/etc/crypttab</filename> and |
| 102 | <filename>/etc/fstab</filename> options</title> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 103 | |
| 104 | <para>Options which influence mounted filesystems and |
| 105 | encrypted volumes.</para> |
| 106 | |
Zbigniew Jędrzejewski-Szmek | 63b03c0 | 2014-06-30 09:27:16 -0400 | [diff] [blame] | 107 | <variablelist id='fstab-options' /> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 108 | </refsect1> |
| 109 | |
| 110 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | 37dac21 | 2019-02-13 10:57:49 +0100 | [diff] [blame] | 111 | <title><citerefentry><refentrytitle>systemd.nspawn</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 112 | directives</title> |
| 113 | |
| 114 | <para>Directives for configuring systemd-nspawn containers.</para> |
| 115 | |
| 116 | <variablelist id='nspawn-directives' /> |
| 117 | </refsect1> |
| 118 | |
| 119 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | d2acdcc | 2019-02-13 10:49:47 +0100 | [diff] [blame] | 120 | <title>Program configuration options</title> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 121 | |
| 122 | <para>Directives for configuring the behaviour of the |
Zbigniew Jędrzejewski-Szmek | d2acdcc | 2019-02-13 10:49:47 +0100 | [diff] [blame] | 123 | systemd process and other tools through configuration files.</para> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 124 | |
Zbigniew Jędrzejewski-Szmek | d2acdcc | 2019-02-13 10:49:47 +0100 | [diff] [blame] | 125 | <variablelist id='config-directives' /> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 126 | </refsect1> |
| 127 | |
| 128 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | 37dac21 | 2019-02-13 10:57:49 +0100 | [diff] [blame] | 129 | <title>Command line options</title> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 130 | |
| 131 | <para>Command-line options accepted by programs in the |
| 132 | systemd suite.</para> |
| 133 | |
| 134 | <variablelist id='options' /> |
| 135 | </refsect1> |
| 136 | |
| 137 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | 785a51e | 2013-06-26 19:48:19 -0400 | [diff] [blame] | 138 | <title>Constants</title> |
| 139 | |
| 140 | <para>Various constant used and/or defined by systemd.</para> |
| 141 | |
| 142 | <variablelist id='constants' /> |
| 143 | </refsect1> |
| 144 | |
| 145 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 146 | <title>Miscellaneous options and directives</title> |
| 147 | |
| 148 | <para>Other configuration elements which don't fit in |
| 149 | any of the above groups.</para> |
| 150 | |
| 151 | <variablelist id='miscellaneous' /> |
| 152 | </refsect1> |
| 153 | |
| 154 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 155 | <title>Files and directories</title> |
| 156 | |
| 157 | <para>Paths and file names referred to in the |
| 158 | documentation.</para> |
| 159 | |
| 160 | <variablelist id='filenames' /> |
| 161 | </refsect1> |
| 162 | |
| 163 | <refsect1> |
Jérémy Rosen | f92c8d1 | 2020-04-18 20:19:50 +0200 | [diff] [blame^] | 164 | <title>D-Bus interfaces</title> |
| 165 | |
| 166 | <para>Interaces exposed over D-Bus.</para> |
| 167 | |
| 168 | <variablelist id='dbus-interface' /> |
| 169 | </refsect1> |
| 170 | |
| 171 | <refsect1> |
| 172 | <title>D-Bus methods</title> |
| 173 | |
| 174 | <para>Methods exposed in the D-Bus interface.</para> |
| 175 | |
| 176 | <variablelist id='dbus-method' /> |
| 177 | </refsect1> |
| 178 | |
| 179 | <refsect1> |
| 180 | <title>D-Bus properties</title> |
| 181 | |
| 182 | <para>Properties exposed in the D-Bus interface.</para> |
| 183 | |
| 184 | <variablelist id='dbus-property' /> |
| 185 | </refsect1> |
| 186 | |
| 187 | <refsect1> |
| 188 | <title>D-Bus signals</title> |
| 189 | |
| 190 | <para>Signals emitted in the D-Bus interface.</para> |
| 191 | |
| 192 | <variablelist id='dbus-signal' /> |
| 193 | </refsect1> |
| 194 | |
| 195 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 196 | <title>Colophon</title> |
| 197 | <para id='colophon' /> |
| 198 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 199 | </refentry> |
| 200 | ''' |
| 201 | |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 202 | COLOPHON = '''\ |
| 203 | This index contains {count} entries in {sections} sections, |
| 204 | referring to {pages} individual manual pages. |
| 205 | ''' |
| 206 | |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 207 | def _extract_directives(directive_groups, formatting, page): |
Zbigniew Jędrzejewski-Szmek | 1a13e31 | 2013-03-29 14:22:27 -0400 | [diff] [blame] | 208 | t = xml_parse(page) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 209 | section = t.find('./refmeta/manvolnum').text |
| 210 | pagename = t.find('./refmeta/refentrytitle').text |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 211 | |
| 212 | storopt = directive_groups['options'] |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 213 | for variablelist in t.iterfind('.//variablelist'): |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 214 | klass = variablelist.attrib.get('class') |
Jérémy Rosen | acbfdec | 2020-04-14 20:15:19 +0200 | [diff] [blame] | 215 | searchpath = variablelist.attrib.get('xpath','./varlistentry/term/varname') |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 216 | storvar = directive_groups[klass or 'miscellaneous'] |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 217 | # <option>s go in OPTIONS, unless class is specified |
Jérémy Rosen | acbfdec | 2020-04-14 20:15:19 +0200 | [diff] [blame] | 218 | for xpath, stor in ((searchpath, storvar), |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 219 | ('./varlistentry/term/option', |
| 220 | storvar if klass else storopt)): |
| 221 | for name in variablelist.iterfind(xpath): |
| 222 | text = re.sub(r'([= ]).*', r'\1', name.text).rstrip() |
Zbigniew Jędrzejewski-Szmek | 8c6c56c | 2019-11-21 22:02:07 +0100 | [diff] [blame] | 223 | if text.startswith('-'): |
| 224 | # for options, merge options with and without mandatory arg |
| 225 | text = text.partition('=')[0] |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 226 | stor[text].append((pagename, section)) |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 227 | if text not in formatting: |
| 228 | # use element as formatted display |
Zbigniew Jędrzejewski-Szmek | f8b6853 | 2019-11-21 20:33:26 +0100 | [diff] [blame] | 229 | if name.text[-1] in "= '": |
Zbigniew Jędrzejewski-Szmek | 699ad6c | 2013-02-27 21:31:02 -0500 | [diff] [blame] | 230 | name.clear() |
| 231 | else: |
| 232 | name.tail = '' |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 233 | name.text = text |
| 234 | formatting[text] = name |
Jérémy Rosen | 8906e26 | 2020-04-18 19:48:13 +0200 | [diff] [blame] | 235 | extra = variablelist.attrib.get('extra-ref') |
| 236 | if extra: |
| 237 | stor[extra].append((pagename, section)) |
| 238 | if extra not in formatting: |
| 239 | elt = tree.Element("varname") |
| 240 | elt.text= extra |
| 241 | formatting[extra] = elt |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 242 | |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 243 | storfile = directive_groups['filenames'] |
Zbigniew Jędrzejewski-Szmek | 845c532 | 2013-05-03 00:55:20 -0400 | [diff] [blame] | 244 | for xpath, absolute_only in (('.//refsynopsisdiv//filename', False), |
| 245 | ('.//refsynopsisdiv//command', False), |
| 246 | ('.//filename', True)): |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 247 | for name in t.iterfind(xpath): |
Zbigniew Jędrzejewski-Szmek | 845c532 | 2013-05-03 00:55:20 -0400 | [diff] [blame] | 248 | if absolute_only and not (name.text and name.text.startswith('/')): |
| 249 | continue |
Zbigniew Jędrzejewski-Szmek | b0343f8 | 2019-11-21 20:22:12 +0100 | [diff] [blame] | 250 | if name.attrib.get('index') == 'false': |
Zbigniew Jędrzejewski-Szmek | 845c532 | 2013-05-03 00:55:20 -0400 | [diff] [blame] | 251 | continue |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 252 | name.tail = '' |
| 253 | if name.text: |
Zbigniew Jędrzejewski-Szmek | 845c532 | 2013-05-03 00:55:20 -0400 | [diff] [blame] | 254 | if name.text.endswith('*'): |
| 255 | name.text = name.text[:-1] |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 256 | if not name.text.startswith('.'): |
| 257 | text = name.text.partition(' ')[0] |
| 258 | if text != name.text: |
| 259 | name.clear() |
| 260 | name.text = text |
Zbigniew Jędrzejewski-Szmek | 845c532 | 2013-05-03 00:55:20 -0400 | [diff] [blame] | 261 | if text.endswith('/'): |
| 262 | text = text[:-1] |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 263 | storfile[text].append((pagename, section)) |
| 264 | if text not in formatting: |
| 265 | # use element as formatted display |
| 266 | formatting[text] = name |
| 267 | else: |
| 268 | text = ' '.join(name.itertext()) |
| 269 | storfile[text].append((pagename, section)) |
| 270 | formatting[text] = name |
| 271 | |
Zbigniew Jędrzejewski-Szmek | 785a51e | 2013-06-26 19:48:19 -0400 | [diff] [blame] | 272 | storfile = directive_groups['constants'] |
| 273 | for name in t.iterfind('.//constant'): |
Zbigniew Jędrzejewski-Szmek | b0343f8 | 2019-11-21 20:22:12 +0100 | [diff] [blame] | 274 | if name.attrib.get('index') == 'false': |
Zbigniew Jędrzejewski-Szmek | 785a51e | 2013-06-26 19:48:19 -0400 | [diff] [blame] | 275 | continue |
| 276 | name.tail = '' |
| 277 | if name.text.startswith('('): # a cast, strip it |
| 278 | name.text = name.text.partition(' ')[2] |
| 279 | storfile[name.text].append((pagename, section)) |
| 280 | formatting[name.text] = name |
| 281 | |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 282 | def _make_section(template, name, directives, formatting): |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 283 | varlist = template.find(".//*[@id='{}']".format(name)) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 284 | for varname, manpages in sorted(directives.items()): |
| 285 | entry = tree.SubElement(varlist, 'varlistentry') |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 286 | term = tree.SubElement(entry, 'term') |
Zbigniew Jędrzejewski-Szmek | 827f70e | 2013-05-29 22:31:20 -0400 | [diff] [blame] | 287 | display = deepcopy(formatting[varname]) |
| 288 | term.append(display) |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 289 | |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 290 | para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para') |
| 291 | |
| 292 | b = None |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 293 | for manpage, manvolume in sorted(set(manpages)): |
Zbigniew Jędrzejewski-Szmek | 827f70e | 2013-05-29 22:31:20 -0400 | [diff] [blame] | 294 | if b is not None: |
| 295 | b.tail = ', ' |
| 296 | b = tree.SubElement(para, 'citerefentry') |
| 297 | c = tree.SubElement(b, 'refentrytitle') |
| 298 | c.text = manpage |
Zbigniew Jędrzejewski-Szmek | 958caa5 | 2015-11-22 23:43:36 -0500 | [diff] [blame] | 299 | c.attrib['target'] = varname |
Zbigniew Jędrzejewski-Szmek | 827f70e | 2013-05-29 22:31:20 -0400 | [diff] [blame] | 300 | d = tree.SubElement(b, 'manvolnum') |
| 301 | d.text = manvolume |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 302 | entry.tail = '\n\n' |
| 303 | |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 304 | def _make_colophon(template, groups): |
| 305 | count = 0 |
| 306 | pages = set() |
| 307 | for group in groups: |
| 308 | count += len(group) |
| 309 | for pagelist in group.values(): |
| 310 | pages |= set(pagelist) |
| 311 | |
| 312 | para = template.find(".//para[@id='colophon']") |
| 313 | para.text = COLOPHON.format(count=count, |
| 314 | sections=len(groups), |
| 315 | pages=len(pages)) |
| 316 | |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 317 | def _make_page(template, directive_groups, formatting): |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 318 | """Create an XML tree from directive_groups. |
| 319 | |
| 320 | directive_groups = { |
| 321 | 'class': {'variable': [('manpage', 'manvolume'), ...], |
| 322 | 'variable2': ...}, |
| 323 | ... |
| 324 | } |
| 325 | """ |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 326 | for name, directives in directive_groups.items(): |
Zbigniew Jędrzejewski-Szmek | 827f70e | 2013-05-29 22:31:20 -0400 | [diff] [blame] | 327 | _make_section(template, name, directives, formatting) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 328 | |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 329 | _make_colophon(template, directive_groups.values()) |
| 330 | |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 331 | return template |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 332 | |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 333 | def make_page(*xml_files): |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 334 | "Extract directives from xml_files and return XML index tree." |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 335 | template = tree.fromstring(TEMPLATE) |
| 336 | names = [vl.get('id') for vl in template.iterfind('.//variablelist')] |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 337 | directive_groups = {name:collections.defaultdict(list) |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 338 | for name in names} |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 339 | formatting = {} |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 340 | for page in xml_files: |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 341 | try: |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 342 | _extract_directives(directive_groups, formatting, page) |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 343 | except Exception: |
| 344 | raise ValueError("failed to process " + page) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 345 | |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 346 | return _make_page(template, directive_groups, formatting) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 347 | |
| 348 | if __name__ == '__main__': |
Zbigniew Jędrzejewski-Szmek | 1a13e31 | 2013-03-29 14:22:27 -0400 | [diff] [blame] | 349 | with open(sys.argv[1], 'wb') as f: |
| 350 | f.write(xml_print(make_page(*sys.argv[2:]))) |