chiark / gitweb /
bus: add kdbus test case
[elogind.git] / make-directive-index.py
index b06a54c..99e7bfa 100755 (executable)
@@ -19,8 +19,8 @@
 
 import sys
 import collections
-import xml.etree.ElementTree as tree
 import re
+from xml_helper import *
 
 TEMPLATE = '''\
 <refentry id="systemd.directives" conditional="HAVE_PYTHON">
@@ -147,6 +147,15 @@ TEMPLATE = '''\
         </refsect1>
 
         <refsect1>
+                <title>Files and directories</title>
+
+                <para>Paths and file names referred to in the
+                documentation.</para>
+
+                <variablelist id='filenames' />
+        </refsect1>
+
+        <refsect1>
                 <title>Colophon</title>
                 <para id='colophon' />
         </refsect1>
@@ -159,13 +168,14 @@ referring to {pages} individual manual pages.
 '''
 
 def _extract_directives(directive_groups, formatting, page):
-    t = tree.parse(page)
+    t = xml_parse(page)
     section = t.find('./refmeta/manvolnum').text
     pagename = t.find('./refmeta/refentrytitle').text
+
+    storopt = directive_groups['options']
     for variablelist in t.iterfind('.//variablelist'):
         klass = variablelist.attrib.get('class')
         storvar = directive_groups[klass or 'miscellaneous']
-        storopt = directive_groups['options']
         # <option>s go in OPTIONS, unless class is specified
         for xpath, stor in (('./varlistentry/term/varname', storvar),
                             ('./varlistentry/term/option',
@@ -175,10 +185,33 @@ def _extract_directives(directive_groups, formatting, page):
                 stor[text].append((pagename, section))
                 if text not in formatting:
                     # use element as formatted display
-                    name.tail = ''
+                    if name.text[-1] in '= ':
+                        name.clear()
+                    else:
+                        name.tail = ''
                     name.text = text
                     formatting[text] = name
 
+    storfile = directive_groups['filenames']
+    for xpath in ('.//refsynopsisdiv//filename',
+                  './/refsynopsisdiv//command'):
+        for name in t.iterfind(xpath):
+            name.tail = ''
+            if name.text:
+                if not name.text.startswith('.'):
+                    text = name.text.partition(' ')[0]
+                    if text != name.text:
+                        name.clear()
+                        name.text = text
+                    storfile[text].append((pagename, section))
+                    if text not in formatting:
+                        # use element as formatted display
+                        formatting[text] = name
+            else:
+                text = ' '.join(name.itertext())
+                storfile[text].append((pagename, section))
+                formatting[text] = name
+
 def _make_section(template, name, directives, formatting):
     varlist = template.find(".//*[@id='{}']".format(name))
     for varname, manpages in sorted(directives.items()):
@@ -244,4 +277,5 @@ def make_page(*xml_files):
     return _make_page(template, directive_groups, formatting)
 
 if __name__ == '__main__':
-    tree.dump(make_page(*sys.argv[1:]))
+    with open(sys.argv[1], 'wb') as f:
+        f.write(xml_print(make_page(*sys.argv[2:])))