chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update TODO
[elogind.git]
/
make-directive-index.py
diff --git
a/make-directive-index.py
b/make-directive-index.py
index c61383b0a46482e46f3e94c2f956d01b7fea607f..468d14da75c53677a02588deca607c4343772217 100755
(executable)
--- a/
make-directive-index.py
+++ b/
make-directive-index.py
@@
-19,8
+19,9
@@
import sys
import collections
import sys
import collections
-import xml.etree.ElementTree as tree
import re
import re
+from xml_helper import *
+from copy import deepcopy
TEMPLATE = '''\
<refentry id="systemd.directives" conditional="HAVE_PYTHON">
TEMPLATE = '''\
<refentry id="systemd.directives" conditional="HAVE_PYTHON">
@@
-168,7
+169,7
@@
referring to {pages} individual manual pages.
'''
def _extract_directives(directive_groups, formatting, page):
'''
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
section = t.find('./refmeta/manvolnum').text
pagename = t.find('./refmeta/refentrytitle').text
@@
-193,16
+194,25
@@
def _extract_directives(directive_groups, formatting, page):
formatting[text] = name
storfile = directive_groups['filenames']
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):
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:
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 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
storfile[text].append((pagename, section))
if text not in formatting:
# use element as formatted display
@@
-217,19
+227,20
@@
def _make_section(template, name, directives, formatting):
for varname, manpages in sorted(directives.items()):
entry = tree.SubElement(varlist, 'varlistentry')
term = tree.SubElement(entry, 'term')
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)):
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):
entry.tail = '\n\n'
def _make_colophon(template, groups):
@@
-255,7
+266,7
@@
def _make_page(template, directive_groups, formatting):
}
"""
for name, directives in directive_groups.items():
}
"""
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())
_make_colophon(template, directive_groups.values())
@@
-277,4
+288,5
@@
def make_page(*xml_files):
return _make_page(template, directive_groups, formatting)
if __name__ == '__main__':
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:])))