summaryrefslogtreecommitdiff
path: root/make-directive-index.py
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2012-11-15 10:10:41 -0500
committerAnthony G. Basile <blueness@gentoo.org>2012-11-15 10:10:41 -0500
commit2944f347d087ff24ec808e4b70fe104a772a97a0 (patch)
treea5de4fbefe16ef359a526442fb41251f123399d5 /make-directive-index.py
parent678b0b89572768b21d8b74360d55b75b233799c4 (diff)
parentd025f1e4dca8fc1436aff76f9e6185fe3e728daa (diff)
Fork of Original Code Base: anongit.freedesktop.org/systemd
This is the initial fork of the code base from freedsktop.org. The code is provided here as a reference of the initial starting point and for possible future checkouts after a large portion of this code is removed. Merge git://anongit.freedesktop.org/systemd/systemd
Diffstat (limited to 'make-directive-index.py')
-rwxr-xr-xmake-directive-index.py149
1 files changed, 149 insertions, 0 deletions
diff --git a/make-directive-index.py b/make-directive-index.py
new file mode 100755
index 0000000000..eaf7019a2b
--- /dev/null
+++ b/make-directive-index.py
@@ -0,0 +1,149 @@
+# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
+#
+# This file is part of systemd.
+#
+# Copyright 2012 Zbigniew Jędrzejewski-Szmek
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# systemd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with systemd; If not, see <http://www.gnu.org/licenses/>.
+
+import sys
+import collections
+import xml.etree.ElementTree as tree
+
+TEMPLATE = '''\
+<refentry id="systemd.directives">
+
+ <refentryinfo>
+ <title>systemd.directives</title>
+ <productname>systemd</productname>
+
+ <authorgroup>
+ <author>
+ <contrib>Developer</contrib>
+ <firstname>Zbigniew</firstname>
+ <surname>Jędrzejewski-Szmek</surname>
+ <email>zbyszek@in.waw.pl</email>
+ </author>
+ </authorgroup>
+ </refentryinfo>
+
+ <refmeta>
+ <refentrytitle>systemd.directives</refentrytitle>
+ <manvolnum>5</manvolnum>
+ </refmeta>
+
+ <refnamediv>
+ <refname>systemd.directives</refname>
+ <refpurpose>Index of configuration directives</refpurpose>
+ </refnamediv>
+
+ <refsect1>
+ <title>Unit directives</title>
+
+ <para>Directives for configuring units, used in unit
+ files.</para>
+
+ <variablelist id='unit-directives' />
+ </refsect1>
+
+ <refsect1>
+ <title>System manager directives</title>
+
+ <para>Directives for configuring the behaviour of the
+ systemd process.</para>
+
+ <variablelist id='systemd-directives' />
+ </refsect1>
+
+ <refsect1>
+ <title>UDEV directives</title>
+
+ <para>Directives for configuring systemd units through the
+ udev database.</para>
+
+ <variablelist id='udev-directives' />
+ </refsect1>
+
+ <refsect1>
+ <title>Journal directives</title>
+
+ <para>Directives for configuring the behaviour of the
+ journald process.</para>
+
+ <variablelist id='journal-directives' />
+ </refsect1>
+</refentry>
+'''
+
+def _extract_directives(directive_groups, page):
+ t = tree.parse(page)
+ section = t.find('./refmeta/manvolnum').text
+ pagename = t.find('./refmeta/refentrytitle').text
+ for variablelist in t.iterfind('.//variablelist'):
+ klass = variablelist.attrib.get('class') or 'unit-directives'
+ stor = directive_groups[klass]
+ for varname in variablelist.iterfind('./varlistentry/term/varname'):
+ text = ''.join(varname.text.partition('=')[:2])
+ stor[text].append((pagename, section))
+
+def _make_section(refentry, name, directives):
+ varlist = refentry.find(".//*[@id='{}']".format(name))
+ for varname, manpages in sorted(directives.items()):
+ entry = tree.SubElement(varlist, 'varlistentry')
+ a = tree.SubElement(tree.SubElement(entry, 'term'), 'varname')
+ a.text = varname
+ para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
+
+ b = None
+ for manpage, manvolume in sorted(manpages):
+ if b is not None:
+ b.tail = ', '
+ b = tree.SubElement(para, 'citerefentry')
+ c = tree.SubElement(b, 'refentrytitle')
+ c.text = manpage
+ d = tree.SubElement(b, 'manvolnum')
+ d.text = manvolume
+ entry.tail = '\n\n'
+
+def _make_page(directive_groups):
+ """Create an XML tree from directive_groups.
+
+ directive_groups = {
+ 'class': {'variable': [('manpage', 'manvolume'), ...],
+ 'variable2': ...},
+ ...
+ }
+ """
+ refentry = tree.fromstring(TEMPLATE)
+
+ for name, directives in directive_groups.items():
+ _make_section(refentry, name, directives)
+
+ return refentry
+
+def make_page(xml_files):
+ "Extract directives from xml_files and return XML index tree."
+ directive_groups = {name:collections.defaultdict(list)
+ for name in ['unit-directives',
+ 'udev-directives',
+ 'systemd-directives',
+ 'journal-directives',
+ ]}
+ for page in xml_files:
+ _extract_directives(directive_groups, page)
+
+ return _make_page(directive_groups)
+
+if __name__ == '__main__':
+ tree.dump(make_page(sys.argv[1:]))