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 | # |
| 5 | # Copyright 2012 Zbigniew Jędrzejewski-Szmek |
| 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 |
| 22 | import xml.etree.ElementTree as tree |
| 23 | |
| 24 | TEMPLATE = '''\ |
| 25 | <refentry id="systemd.directives"> |
| 26 | |
| 27 | <refentryinfo> |
| 28 | <title>systemd.directives</title> |
| 29 | <productname>systemd</productname> |
| 30 | |
| 31 | <authorgroup> |
| 32 | <author> |
| 33 | <contrib>Developer</contrib> |
| 34 | <firstname>Zbigniew</firstname> |
| 35 | <surname>Jędrzejewski-Szmek</surname> |
| 36 | <email>zbyszek@in.waw.pl</email> |
| 37 | </author> |
| 38 | </authorgroup> |
| 39 | </refentryinfo> |
| 40 | |
| 41 | <refmeta> |
| 42 | <refentrytitle>systemd.directives</refentrytitle> |
Zbigniew Jędrzejewski-Szmek | 9cc2c8b | 2013-01-14 22:08:33 -0500 | [diff] [blame] | 43 | <manvolnum>7</manvolnum> |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 44 | </refmeta> |
| 45 | |
| 46 | <refnamediv> |
| 47 | <refname>systemd.directives</refname> |
| 48 | <refpurpose>Index of configuration directives</refpurpose> |
| 49 | </refnamediv> |
| 50 | |
| 51 | <refsect1> |
| 52 | <title>Unit directives</title> |
| 53 | |
| 54 | <para>Directives for configuring units, used in unit |
| 55 | files.</para> |
| 56 | |
| 57 | <variablelist id='unit-directives' /> |
| 58 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | e1abd3e | 2012-09-16 11:11:34 +0200 | [diff] [blame] | 59 | |
| 60 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | ffafe91 | 2012-08-10 19:14:30 +0200 | [diff] [blame] | 61 | <title>System manager directives</title> |
| 62 | |
| 63 | <para>Directives for configuring the behaviour of the |
| 64 | systemd process.</para> |
| 65 | |
| 66 | <variablelist id='systemd-directives' /> |
| 67 | </refsect1> |
| 68 | |
| 69 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | 08177c8 | 2013-01-14 21:58:22 -0500 | [diff] [blame] | 70 | <title>Options on the kernel command line</title> |
| 71 | |
| 72 | <para>Kernel boot options for configuring the behaviour of the |
| 73 | systemd process.</para> |
| 74 | |
| 75 | <variablelist id='kernel-commandline-directives' /> |
| 76 | </refsect1> |
| 77 | |
| 78 | <refsect1> |
| 79 | <title>Environment variables</title> |
| 80 | |
| 81 | <para>Environment variables understood by the systemd process.</para> |
| 82 | |
| 83 | <variablelist id='environment-variables' /> |
| 84 | </refsect1> |
| 85 | |
| 86 | <refsect1> |
Zbigniew Jędrzejewski-Szmek | e1abd3e | 2012-09-16 11:11:34 +0200 | [diff] [blame] | 87 | <title>UDEV directives</title> |
| 88 | |
| 89 | <para>Directives for configuring systemd units through the |
| 90 | udev database.</para> |
| 91 | |
| 92 | <variablelist id='udev-directives' /> |
| 93 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | f6c2e28 | 2012-08-10 19:35:43 +0200 | [diff] [blame] | 94 | |
| 95 | <refsect1> |
| 96 | <title>Journal directives</title> |
| 97 | |
| 98 | <para>Directives for configuring the behaviour of the |
| 99 | journald process.</para> |
| 100 | |
| 101 | <variablelist id='journal-directives' /> |
| 102 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | 4a431c9 | 2013-01-14 20:18:36 -0500 | [diff] [blame] | 103 | |
| 104 | <refsect1> |
| 105 | <title>bootchart.conf directives</title> |
| 106 | |
| 107 | <para>Directives for configuring the behaviour of the |
| 108 | systemd-bootchart process.</para> |
| 109 | |
| 110 | <variablelist id='bootchart-directives' /> |
| 111 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 112 | |
| 113 | <refsect1> |
| 114 | <title>Colophon</title> |
| 115 | <para id='colophon' /> |
| 116 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 117 | </refentry> |
| 118 | ''' |
| 119 | |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 120 | COLOPHON = '''\ |
| 121 | This index contains {count} entries in {sections} sections, |
| 122 | referring to {pages} individual manual pages. |
| 123 | ''' |
| 124 | |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 125 | def _extract_directives(directive_groups, page): |
| 126 | t = tree.parse(page) |
| 127 | section = t.find('./refmeta/manvolnum').text |
| 128 | pagename = t.find('./refmeta/refentrytitle').text |
| 129 | for variablelist in t.iterfind('.//variablelist'): |
| 130 | klass = variablelist.attrib.get('class') or 'unit-directives' |
| 131 | stor = directive_groups[klass] |
| 132 | for varname in variablelist.iterfind('./varlistentry/term/varname'): |
| 133 | text = ''.join(varname.text.partition('=')[:2]) |
| 134 | stor[text].append((pagename, section)) |
| 135 | |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 136 | def _make_section(template, name, directives): |
| 137 | varlist = template.find(".//*[@id='{}']".format(name)) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 138 | for varname, manpages in sorted(directives.items()): |
| 139 | entry = tree.SubElement(varlist, 'varlistentry') |
| 140 | a = tree.SubElement(tree.SubElement(entry, 'term'), 'varname') |
| 141 | a.text = varname |
| 142 | para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para') |
| 143 | |
| 144 | b = None |
| 145 | for manpage, manvolume in sorted(manpages): |
| 146 | if b is not None: |
| 147 | b.tail = ', ' |
| 148 | b = tree.SubElement(para, 'citerefentry') |
| 149 | c = tree.SubElement(b, 'refentrytitle') |
| 150 | c.text = manpage |
| 151 | d = tree.SubElement(b, 'manvolnum') |
| 152 | d.text = manvolume |
| 153 | entry.tail = '\n\n' |
| 154 | |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 155 | def _make_colophon(template, groups): |
| 156 | count = 0 |
| 157 | pages = set() |
| 158 | for group in groups: |
| 159 | count += len(group) |
| 160 | for pagelist in group.values(): |
| 161 | pages |= set(pagelist) |
| 162 | |
| 163 | para = template.find(".//para[@id='colophon']") |
| 164 | para.text = COLOPHON.format(count=count, |
| 165 | sections=len(groups), |
| 166 | pages=len(pages)) |
| 167 | |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 168 | def _make_page(template, directive_groups): |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 169 | """Create an XML tree from directive_groups. |
| 170 | |
| 171 | directive_groups = { |
| 172 | 'class': {'variable': [('manpage', 'manvolume'), ...], |
| 173 | 'variable2': ...}, |
| 174 | ... |
| 175 | } |
| 176 | """ |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 177 | for name, directives in directive_groups.items(): |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 178 | _make_section(template, name, directives) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 179 | |
Zbigniew Jędrzejewski-Szmek | 0acfdd6 | 2013-01-14 21:34:19 -0500 | [diff] [blame] | 180 | _make_colophon(template, directive_groups.values()) |
| 181 | |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 182 | return template |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 183 | |
| 184 | def make_page(xml_files): |
| 185 | "Extract directives from xml_files and return XML index tree." |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 186 | template = tree.fromstring(TEMPLATE) |
| 187 | names = [vl.get('id') for vl in template.iterfind('.//variablelist')] |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 188 | directive_groups = {name:collections.defaultdict(list) |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 189 | for name in names} |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 190 | for page in xml_files: |
| 191 | _extract_directives(directive_groups, page) |
| 192 | |
Zbigniew Jędrzejewski-Szmek | eeb019b | 2013-01-14 21:02:49 -0500 | [diff] [blame] | 193 | return _make_page(template, directive_groups) |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 194 | |
| 195 | if __name__ == '__main__': |
| 196 | tree.dump(make_page(sys.argv[1:])) |