Commit d970bd6d authored by Zbigniew Jędrzejewski-Szmek's avatar Zbigniew Jędrzejewski-Szmek
Browse files

make-directive-index: use original XML as index entries

udev(7) fields are now display in whole, which looks
much better.
parent ccc9a4f9
...@@ -158,7 +158,7 @@ This index contains {count} entries in {sections} sections, ...@@ -158,7 +158,7 @@ This index contains {count} entries in {sections} sections,
referring to {pages} individual manual pages. referring to {pages} individual manual pages.
''' '''
def _extract_directives(directive_groups, page): def _extract_directives(directive_groups, formatting, page):
t = tree.parse(page) t = tree.parse(page)
section = t.find('./refmeta/manvolnum').text section = t.find('./refmeta/manvolnum').text
pagename = t.find('./refmeta/refentrytitle').text pagename = t.find('./refmeta/refentrytitle').text
...@@ -173,13 +173,19 @@ def _extract_directives(directive_groups, page): ...@@ -173,13 +173,19 @@ def _extract_directives(directive_groups, page):
for name in variablelist.iterfind(xpath): for name in variablelist.iterfind(xpath):
text = re.sub(r'([= ]).*', r'\1', name.text).rstrip() text = re.sub(r'([= ]).*', r'\1', name.text).rstrip()
stor[text].append((pagename, section)) stor[text].append((pagename, section))
if text not in formatting:
# use element as formatted display
name.tail = ''
name.text = text
formatting[text] = name
def _make_section(template, name, directives): def _make_section(template, name, directives, formatting):
varlist = template.find(".//*[@id='{}']".format(name)) varlist = template.find(".//*[@id='{}']".format(name))
for varname, manpages in sorted(directives.items()): for varname, manpages in sorted(directives.items()):
entry = tree.SubElement(varlist, 'varlistentry') entry = tree.SubElement(varlist, 'varlistentry')
a = tree.SubElement(tree.SubElement(entry, 'term'), 'varname') term = tree.SubElement(entry, 'term')
a.text = varname term.append(formatting[varname])
para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para') para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
b = None b = None
...@@ -206,7 +212,7 @@ def _make_colophon(template, groups): ...@@ -206,7 +212,7 @@ def _make_colophon(template, groups):
sections=len(groups), sections=len(groups),
pages=len(pages)) pages=len(pages))
def _make_page(template, directive_groups): def _make_page(template, directive_groups, formatting):
"""Create an XML tree from directive_groups. """Create an XML tree from directive_groups.
directive_groups = { directive_groups = {
...@@ -216,7 +222,7 @@ def _make_page(template, directive_groups): ...@@ -216,7 +222,7 @@ def _make_page(template, directive_groups):
} }
""" """
for name, directives in directive_groups.items(): for name, directives in directive_groups.items():
_make_section(template, name, directives) _make_section(template, name, directives, formatting)
_make_colophon(template, directive_groups.values()) _make_colophon(template, directive_groups.values())
...@@ -228,13 +234,14 @@ def make_page(*xml_files): ...@@ -228,13 +234,14 @@ def make_page(*xml_files):
names = [vl.get('id') for vl in template.iterfind('.//variablelist')] names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
directive_groups = {name:collections.defaultdict(list) directive_groups = {name:collections.defaultdict(list)
for name in names} for name in names}
formatting = {}
for page in xml_files: for page in xml_files:
try: try:
_extract_directives(directive_groups, page) _extract_directives(directive_groups, formatting, page)
except Exception: except Exception:
raise ValueError("failed to process " + page) raise ValueError("failed to process " + page)
return _make_page(template, directive_groups) return _make_page(template, directive_groups, formatting)
if __name__ == '__main__': if __name__ == '__main__':
tree.dump(make_page(*sys.argv[1:])) tree.dump(make_page(*sys.argv[1:]))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment