summaryrefslogtreecommitdiff
path: root/make-man-index.py
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-29 14:22:27 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-29 20:30:21 -0400
commit1a13e31d275430ffba713c8a68ee7f22093c29e0 (patch)
tree66b0b3e91d22fce58affea603c2a5cbf6eb0c6a9 /make-man-index.py
parent4e7b3c20e00c40372c551bd42c57e40500f4ceb4 (diff)
build-sys,man: use XML entities to substite strings
This makes it easier to add substitutions to man pages, avoiding the separate transformation step. mkdir -p's are removed from the rule, because xsltproc will will create directories on it's own. All in all, two or three forks per man page are avoided, which should make things marginally faster. Unfortunately python parsers must too be tweaked to handle entities. This isn't particularly easy: with lxml a custom Resolver can be used, but the stdlib etree doesn't support external entities *at all*. So when running without lxml, the entities are just removed. Right now it doesn't matter, since the entities are not indexed anyway. But I intend to add indexing of filenames in the near future, and then the index generated without lxml might be missing a few lines. Oh well.
Diffstat (limited to 'make-man-index.py')
-rwxr-xr-xmake-man-index.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/make-man-index.py b/make-man-index.py
index d9ab5cc75..74a47b821 100755
--- a/make-man-index.py
+++ b/make-man-index.py
@@ -19,14 +19,10 @@
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
import collections
-try:
- from lxml import etree as tree
- PRETTY = dict(pretty_print=True)
-except ImportError:
- import xml.etree.ElementTree as tree
- PRETTY = {}
import sys
import re
+from xml_helper import *
+
MDASH = ' — ' if sys.version_info.major >= 3 else ' -- '
TEMPLATE = '''\
@@ -72,6 +68,7 @@ SUMMARY = '''\
COUNTS = '\
This index contains {count} entries, referring to {pages} individual manual pages.'
+
def check_id(page, t):
id = t.getroot().get('id')
if not re.search('/' + id + '[.]', page):
@@ -80,7 +77,7 @@ def check_id(page, t):
def make_index(pages):
index = collections.defaultdict(list)
for p in pages:
- t = tree.parse(p)
+ t = xml_parse(p)
check_id(p, t)
section = t.find('./refmeta/manvolnum').text
refname = t.find('./refnamediv/refname').text
@@ -123,7 +120,7 @@ def add_summary(template, indexpages):
para = template.find(".//para[@id='counts']")
para.text = COUNTS.format(count=count, pages=len(pages))
-def make_page(xml_files):
+def make_page(*xml_files):
template = tree.fromstring(TEMPLATE)
index = make_index(xml_files)
@@ -135,4 +132,5 @@ def make_page(xml_files):
return template
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:])))