X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=make-directive-index.py;h=396947b3030f6c271fcec46d55e911abfbbc3a8a;hp=039efaa4345001fe4f22fa16c07c3fcc55ae632b;hb=7ecec4705c0cacb1446af0eb7a4aee66c00d058f;hpb=80cb917e6248c15fd4a95d29954b3fd1e3d66b06 diff --git a/make-directive-index.py b/make-directive-index.py index 039efaa43..396947b30 100755 --- a/make-directive-index.py +++ b/make-directive-index.py @@ -19,13 +19,8 @@ import sys import collections -try: - from lxml import etree as tree - PRETTY = dict(pretty_print=True) -except ImportError: - import xml.etree.ElementTree as tree - PRETTY = {} import re +from xml_helper import * TEMPLATE = '''\ @@ -173,7 +168,7 @@ 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 @@ -198,16 +193,25 @@ def _extract_directives(directive_groups, formatting, page): formatting[text] = name storfile = directive_groups['filenames'] - for xpath in ('.//refsynopsisdiv//filename', - './/refsynopsisdiv//command'): + 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 @@ -282,4 +286,5 @@ def make_page(*xml_files): return _make_page(template, directive_groups, formatting) if __name__ == '__main__': - tree.dump(make_page(*sys.argv[1:]), **PRETTY) + with open(sys.argv[1], 'wb') as f: + f.write(xml_print(make_page(*sys.argv[2:])))