chiark / gitweb /
journal: fail silently in sd_j_sendv() if journal is unavailable
[elogind.git] / make-directive-index.py
index b06a54c1d50a85286006e4d10c6487f4681c268f..2ff304fddc1ca14f743c58409b1d6d24f5ae5779 100755 (executable)
@@ -19,8 +19,9 @@
 
 import sys
 import collections
-import xml.etree.ElementTree as tree
 import re
+from xml_helper import *
+from copy import deepcopy
 
 TEMPLATE = '''\
 <refentry id="systemd.directives" conditional="HAVE_PYTHON">
@@ -85,6 +86,16 @@ TEMPLATE = '''\
                 <variablelist id='udev-directives' />
         </refsect1>
 
+        <refsect1>
+                <title>Network directives</title>
+
+                <para>Directives for configuring network links through the
+                net-setup-link udev builtin and networks through
+                systemd-networkd.</para>
+
+                <variablelist id='network-directives' />
+        </refsect1>
+
         <refsect1>
                 <title>Journal fields</title>
 
@@ -137,6 +148,14 @@ TEMPLATE = '''\
                 <variablelist id='options' />
         </refsect1>
 
+        <refsect1>
+                <title>Constants</title>
+
+                <para>Various constant used and/or defined by systemd.</para>
+
+                <variablelist id='constants' />
+        </refsect1>
+
         <refsect1>
                 <title>Miscellaneous options and directives</title>
 
@@ -146,6 +165,15 @@ TEMPLATE = '''\
                 <variablelist id='miscellaneous' />
         </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' />
@@ -159,13 +187,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,28 +204,71 @@ 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, absolute_only in (('.//refsynopsisdiv//filename', False),
+                                 ('.//refsynopsisdiv//command', False),
+                                 ('.//filename', True)):
+        for name in t.iterfind(xpath):
+            if absolute_only and not (name.text and name.text.startswith('/')):
+                continue
+            if name.attrib.get('noindex'):
+                continue
+            name.tail = ''
+            if name.text:
+                if name.text.endswith('*'):
+                    name.text = name.text[:-1]
+                if not name.text.startswith('.'):
+                    text = name.text.partition(' ')[0]
+                    if text != name.text:
+                        name.clear()
+                        name.text = text
+                    if text.endswith('/'):
+                        text = text[:-1]
+                    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
+
+    storfile = directive_groups['constants']
+    for name in t.iterfind('.//constant'):
+        if name.attrib.get('noindex'):
+            continue
+        name.tail = ''
+        if name.text.startswith('('): # a cast, strip it
+            name.text = name.text.partition(' ')[2]
+        storfile[name.text].append((pagename, section))
+        formatting[name.text] = name
+
 def _make_section(template, name, directives, formatting):
     varlist = template.find(".//*[@id='{}']".format(name))
     for varname, manpages in sorted(directives.items()):
         entry = tree.SubElement(varlist, 'varlistentry')
         term = tree.SubElement(entry, 'term')
-        term.append(formatting[varname])
+        display = deepcopy(formatting[varname])
+        term.append(display)
 
         para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
 
         b = None
         for manpage, manvolume in sorted(set(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
+            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_colophon(template, groups):
@@ -222,7 +294,7 @@ def _make_page(template, directive_groups, formatting):
     }
     """
     for name, directives in directive_groups.items():
-            _make_section(template, name, directives, formatting)
+        _make_section(template, name, directives, formatting)
 
     _make_colophon(template, directive_groups.values())
 
@@ -244,4 +316,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:])))