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> |
| 43 | <manvolnum>5</manvolnum> |
| 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 | e1abd3e | 2012-09-16 11:11:34 +0200 | [diff] [blame] | 70 | <title>UDEV directives</title> |
| 71 | |
| 72 | <para>Directives for configuring systemd units through the |
| 73 | udev database.</para> |
| 74 | |
| 75 | <variablelist id='udev-directives' /> |
| 76 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | f6c2e28 | 2012-08-10 19:35:43 +0200 | [diff] [blame] | 77 | |
| 78 | <refsect1> |
| 79 | <title>Journal directives</title> |
| 80 | |
| 81 | <para>Directives for configuring the behaviour of the |
| 82 | journald process.</para> |
| 83 | |
| 84 | <variablelist id='journal-directives' /> |
| 85 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | 4a431c9 | 2013-01-14 20:18:36 -0500 | [diff] [blame^] | 86 | |
| 87 | <refsect1> |
| 88 | <title>bootchart.conf directives</title> |
| 89 | |
| 90 | <para>Directives for configuring the behaviour of the |
| 91 | systemd-bootchart process.</para> |
| 92 | |
| 93 | <variablelist id='bootchart-directives' /> |
| 94 | </refsect1> |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 95 | </refentry> |
| 96 | ''' |
| 97 | |
| 98 | def _extract_directives(directive_groups, page): |
| 99 | t = tree.parse(page) |
| 100 | section = t.find('./refmeta/manvolnum').text |
| 101 | pagename = t.find('./refmeta/refentrytitle').text |
| 102 | for variablelist in t.iterfind('.//variablelist'): |
| 103 | klass = variablelist.attrib.get('class') or 'unit-directives' |
| 104 | stor = directive_groups[klass] |
| 105 | for varname in variablelist.iterfind('./varlistentry/term/varname'): |
| 106 | text = ''.join(varname.text.partition('=')[:2]) |
| 107 | stor[text].append((pagename, section)) |
| 108 | |
| 109 | def _make_section(refentry, name, directives): |
| 110 | varlist = refentry.find(".//*[@id='{}']".format(name)) |
| 111 | for varname, manpages in sorted(directives.items()): |
| 112 | entry = tree.SubElement(varlist, 'varlistentry') |
| 113 | a = tree.SubElement(tree.SubElement(entry, 'term'), 'varname') |
| 114 | a.text = varname |
| 115 | para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para') |
| 116 | |
| 117 | b = None |
| 118 | for manpage, manvolume in sorted(manpages): |
| 119 | if b is not None: |
| 120 | b.tail = ', ' |
| 121 | b = tree.SubElement(para, 'citerefentry') |
| 122 | c = tree.SubElement(b, 'refentrytitle') |
| 123 | c.text = manpage |
| 124 | d = tree.SubElement(b, 'manvolnum') |
| 125 | d.text = manvolume |
| 126 | entry.tail = '\n\n' |
| 127 | |
| 128 | def _make_page(directive_groups): |
| 129 | """Create an XML tree from directive_groups. |
| 130 | |
| 131 | directive_groups = { |
| 132 | 'class': {'variable': [('manpage', 'manvolume'), ...], |
| 133 | 'variable2': ...}, |
| 134 | ... |
| 135 | } |
| 136 | """ |
| 137 | refentry = tree.fromstring(TEMPLATE) |
| 138 | |
| 139 | for name, directives in directive_groups.items(): |
| 140 | _make_section(refentry, name, directives) |
| 141 | |
| 142 | return refentry |
| 143 | |
| 144 | def make_page(xml_files): |
| 145 | "Extract directives from xml_files and return XML index tree." |
| 146 | directive_groups = {name:collections.defaultdict(list) |
| 147 | for name in ['unit-directives', |
Zbigniew Jędrzejewski-Szmek | e1abd3e | 2012-09-16 11:11:34 +0200 | [diff] [blame] | 148 | 'udev-directives', |
Zbigniew Jędrzejewski-Szmek | ffafe91 | 2012-08-10 19:14:30 +0200 | [diff] [blame] | 149 | 'systemd-directives', |
Zbigniew Jędrzejewski-Szmek | f6c2e28 | 2012-08-10 19:35:43 +0200 | [diff] [blame] | 150 | 'journal-directives', |
Zbigniew Jędrzejewski-Szmek | 4a431c9 | 2013-01-14 20:18:36 -0500 | [diff] [blame^] | 151 | 'bootchart-directives', |
Zbigniew Jędrzejewski-Szmek | d9cfd69 | 2012-08-09 18:08:14 +0200 | [diff] [blame] | 152 | ]} |
| 153 | for page in xml_files: |
| 154 | _extract_directives(directive_groups, page) |
| 155 | |
| 156 | return _make_page(directive_groups) |
| 157 | |
| 158 | if __name__ == '__main__': |
| 159 | tree.dump(make_page(sys.argv[1:])) |