Zbigniew Jędrzejewski-Szmek | e7098b6 | 2012-11-13 18:39:18 +0100 | [diff] [blame] | 1 | # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ |
| 2 | # |
| 3 | # This file is part of systemd. |
| 4 | # |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 5 | # Copyright 2012-2013 Zbigniew Jędrzejewski-Szmek |
Zbigniew Jędrzejewski-Szmek | e7098b6 | 2012-11-13 18:39:18 +0100 | [diff] [blame] | 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 | |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 20 | import sys |
| 21 | import collections |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 22 | import re |
Zbigniew Jędrzejewski-Szmek | 1a13e31 | 2013-03-29 14:22:27 -0400 | [diff] [blame] | 23 | from xml_helper import * |
Zbigniew Jędrzejewski-Szmek | 827f70e | 2013-05-29 22:31:20 -0400 | [diff] [blame] | 24 | from copy import deepcopy |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 25 | |
| 26 | TEMPLATE = '''\ |
Zbigniew Jędrzejewski-Szmek | 56ba3c7 | 2013-02-02 22:47:47 -0500 | [diff] [blame] | 27 | <refentry id="systemd.directives" conditional="HAVE_PYTHON"> |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 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> |
Zbigniew Jędrzejewski-Szmek | 9cc2c8b | 2013-01-14 22:08:33 -0500 | [diff] [blame] | 45 | <manvolnum>7</manvolnum> |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 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> |
Zbigniew Jędrzejewski-Szmek | e1abd3e | 2012-09-16 11:11:34 +0200 | [diff] [blame] | 61 | |
| 62 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | 08177c8 | 2013-01-14 21:58:22 -0500 | [diff] [blame] | 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 | |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 68 | <variablelist id='kernel-commandline-options' /> |
Zbigniew Jędrzejewski-Szmek | 08177c8 | 2013-01-14 21:58:22 -0500 | [diff] [blame] | 69 | </refsect1> |
| 70 | |
| 71 | <refsect1> |
| 72 | <title>Environment variables</title> |
| 73 | |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 74 | <para>Environment variables understood by the systemd |
| 75 | manager and other programs.</para> |
Zbigniew Jędrzejewski-Szmek | 08177c8 | 2013-01-14 21:58:22 -0500 | [diff] [blame] | 76 | |
| 77 | <variablelist id='environment-variables' /> |
| 78 | </refsect1> |
| 79 | |
| 80 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | e1abd3e | 2012-09-16 11:11:34 +0200 | [diff] [blame] | 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> |
Zbigniew Jędrzejewski-Szmek | f6c2e28 | 2012-08-10 19:35:43 +0200 | [diff] [blame] | 88 | |
| 89 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 90 | <title>Journal fields</title> |
Zbigniew Jędrzejewski-Szmek | f6c2e28 | 2012-08-10 19:35:43 +0200 | [diff] [blame] | 91 | |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 92 | <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] | 93 | |
| 94 | <variablelist id='journal-directives' /> |
| 95 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | 4a431c9 | 2013-01-14 20:18:36 -0500 | [diff] [blame] | 96 | |
| 97 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 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 | |
| 123 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | 4a431c9 | 2013-01-14 20:18:36 -0500 | [diff] [blame] | 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> |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 131 | |
| 132 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 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 | |
| 150 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 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 | |
| 159 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 160 | <title>Colophon</title> |
| 161 | <para id='colophon' /> |
| 162 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 163 | </refentry> |
| 164 | ''' |
| 165 | |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 166 | COLOPHON = '''\ |
| 167 | This index contains {count} entries in {sections} sections, |
| 168 | referring to {pages} individual manual pages. |
| 169 | ''' |
| 170 | |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 171 | def _extract_directives(directive_groups, formatting, page): |
Zbigniew Jędrzejewski-Szmek | 1a13e31 | 2013-03-29 14:22:27 -0400 | [diff] [blame] | 172 | t = xml_parse(page) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 173 | section = t.find('./refmeta/manvolnum').text |
| 174 | pagename = t.find('./refmeta/refentrytitle').text |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 175 | |
| 176 | storopt = directive_groups['options'] |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 177 | for variablelist in t.iterfind('.//variablelist'): |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 178 | klass = variablelist.attrib.get('class') |
| 179 | storvar = directive_groups[klass or 'miscellaneous'] |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 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)) |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 187 | if text not in formatting: |
| 188 | # use element as formatted display |
Zbigniew Jędrzejewski-Szmek | 699ad6c | 2013-02-27 21:31:02 -0500 | [diff] [blame] | 189 | if name.text[-1] in '= ': |
| 190 | name.clear() |
| 191 | else: |
| 192 | name.tail = '' |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 193 | name.text = text |
| 194 | formatting[text] = name |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 195 | |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 196 | storfile = directive_groups['filenames'] |
Zbigniew Jędrzejewski-Szmek | 845c532 | 2013-05-03 00:55:20 -0400 | [diff] [blame] | 197 | for xpath, absolute_only in (('.//refsynopsisdiv//filename', False), |
| 198 | ('.//refsynopsisdiv//command', False), |
| 199 | ('.//filename', True)): |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 200 | for name in t.iterfind(xpath): |
Zbigniew Jędrzejewski-Szmek | 845c532 | 2013-05-03 00:55:20 -0400 | [diff] [blame] | 201 | if absolute_only and not (name.text and name.text.startswith('/')): |
| 202 | continue |
| 203 | if name.attrib.get('noindex'): |
| 204 | continue |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 205 | name.tail = '' |
| 206 | if name.text: |
Zbigniew Jędrzejewski-Szmek | 845c532 | 2013-05-03 00:55:20 -0400 | [diff] [blame] | 207 | if name.text.endswith('*'): |
| 208 | name.text = name.text[:-1] |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 209 | if not name.text.startswith('.'): |
| 210 | text = name.text.partition(' ')[0] |
| 211 | if text != name.text: |
| 212 | name.clear() |
| 213 | name.text = text |
Zbigniew Jędrzejewski-Szmek | 845c532 | 2013-05-03 00:55:20 -0400 | [diff] [blame] | 214 | if text.endswith('/'): |
| 215 | text = text[:-1] |
Zbigniew Jędrzejewski-Szmek | a4e0b94 | 2013-02-13 21:51:31 -0500 | [diff] [blame] | 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 | |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 225 | def _make_section(template, name, directives, formatting): |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 226 | varlist = template.find(".//*[@id='{}']".format(name)) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 227 | for varname, manpages in sorted(directives.items()): |
| 228 | entry = tree.SubElement(varlist, 'varlistentry') |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 229 | term = tree.SubElement(entry, 'term') |
Zbigniew Jędrzejewski-Szmek | 827f70e | 2013-05-29 22:31:20 -0400 | [diff] [blame] | 230 | display = deepcopy(formatting[varname]) |
| 231 | term.append(display) |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 232 | |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 233 | para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para') |
| 234 | |
| 235 | b = None |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 236 | for manpage, manvolume in sorted(set(manpages)): |
Zbigniew Jędrzejewski-Szmek | 827f70e | 2013-05-29 22:31:20 -0400 | [diff] [blame] | 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 |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 244 | entry.tail = '\n\n' |
| 245 | |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 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 | |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 259 | def _make_page(template, directive_groups, formatting): |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 260 | """Create an XML tree from directive_groups. |
| 261 | |
| 262 | directive_groups = { |
| 263 | 'class': {'variable': [('manpage', 'manvolume'), ...], |
| 264 | 'variable2': ...}, |
| 265 | ... |
| 266 | } |
| 267 | """ |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 268 | for name, directives in directive_groups.items(): |
Zbigniew Jędrzejewski-Szmek | 827f70e | 2013-05-29 22:31:20 -0400 | [diff] [blame] | 269 | _make_section(template, name, directives, formatting) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 270 | |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 271 | _make_colophon(template, directive_groups.values()) |
| 272 | |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 273 | return template |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 274 | |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 275 | def make_page(*xml_files): |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 276 | "Extract directives from xml_files and return XML index tree." |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 277 | template = tree.fromstring(TEMPLATE) |
| 278 | names = [vl.get('id') for vl in template.iterfind('.//variablelist')] |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 279 | directive_groups = {name:collections.defaultdict(list) |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 280 | for name in names} |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 281 | formatting = {} |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 282 | for page in xml_files: |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 283 | try: |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 284 | _extract_directives(directive_groups, formatting, page) |
Zbigniew Jędrzejewski-Szmek | ccc9a4f | 2013-01-26 10:47:16 -0500 | [diff] [blame] | 285 | except Exception: |
| 286 | raise ValueError("failed to process " + page) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 287 | |
Zbigniew Jędrzejewski-Szmek | d970bd6 | 2013-01-26 11:27:35 -0500 | [diff] [blame] | 288 | return _make_page(template, directive_groups, formatting) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 289 | |
| 290 | if __name__ == '__main__': |
Zbigniew Jędrzejewski-Szmek | 1a13e31 | 2013-03-29 14:22:27 -0400 | [diff] [blame] | 291 | with open(sys.argv[1], 'wb') as f: |
| 292 | f.write(xml_print(make_page(*sys.argv[2:]))) |