[systemd-devel] [PATCH]: fix doc generation with python3.x in non utf-8 locales

Kelly Anderson kelly at xilka.com
Tue Mar 26 16:00:23 PDT 2013


Hi,

Here is a patch that fixed documentation with python 3.x in non utf-8 
locales.
Specifically in my locale latin-1 is the default setting for output 
going to stdout,
which causes it to fail. By writing directly to file we are able to set 
the locale to utf-8.
This also eliminates a call to tree.dump which has been deprecated and was
intended for debug use only.

--- ./make-directive-index.py.orig 2013-03-26 08:51:57.000000000 -0600
+++ ./make-directive-index.py 2013-03-26 16:53:56.779139884 -0600
@@ -19,12 +19,13 @@

import sys
import collections
+
try:
from lxml import etree as tree
- PRETTY = dict(pretty_print=True)
+ PRETTY = dict(pretty_print=True, encoding='utf-8')
except ImportError:
import xml.etree.ElementTree as tree
- PRETTY = {}
+ PRETTY = dict(encoding='utf-8')
import re

TEMPLATE = '''\
@@ -174,6 +175,7 @@ referring to {pages} individual manual p

def _extract_directives(directive_groups, formatting, page):
t = tree.parse(page)
+
section = t.find('./refmeta/manvolnum').text
pagename = t.find('./refmeta/refentrytitle').text

@@ -282,4 +284,7 @@ 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:
+ s = tree.tostring(make_page(*sys.argv[2:]), **PRETTY)
+ f.write(s)
+
--- ./Makefile.am.orig 2013-03-26 08:51:57.000000000 -0600
+++ ./Makefile.am 2013-03-26 16:53:04.590988127 -0600
@@ -566,11 +566,13 @@ update-man-list: make-man-rules.py $(XML

man/systemd.index.xml: make-man-index.py $(NON_INDEX_XML_FILES)
$(AM_V_at)$(MKDIR_P) $(dir $@)
- $(AM_V_GEN)$(PYTHON) $^ > $@
+ $(AM_V_GEN)$(PYTHON) $< $@ $(NON_INDEX_XML_FILES)

-man/systemd.directives.xml: make-directive-index.py $(filter-out 
man/systemd.directives.xml,$(NON_INDEX_XML_FILES))
+NON_INDEX_XML_FILES2=$(filter-out 
man/systemd.directives.xml,$(NON_INDEX_XML_FILES))
+
+man/systemd.directives.xml: make-directive-index.py $(NON_INDEX_XML_FILES2)
$(AM_V_at)$(MKDIR_P) $(dir $@)
- $(AM_V_GEN)$(PYTHON) $^ > $@
+ $(AM_V_GEN)$(PYTHON) $< $@ $(NON_INDEX_XML_FILES2)

EXTRA_DIST += \
man/systemd.index.xml \
--- ./make-man-index.py.orig 2013-03-26 08:51:57.000000000 -0600
+++ ./make-man-index.py 2013-03-26 16:53:04.590988127 -0600
@@ -21,10 +21,10 @@
import collections
try:
from lxml import etree as tree
- PRETTY = dict(pretty_print=True)
+ PRETTY = dict(encoding='utf-8', pretty_print=True)
except ImportError:
import xml.etree.ElementTree as tree
- PRETTY = {}
+ PRETTY = dict(encoding='utf-8')
import sys
import re
MDASH = ' — ' if sys.version_info.major >= 3 else ' -- '
@@ -135,4 +135,7 @@ 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:
+ s = tree.tostring(make_page(sys.argv[2:]), **PRETTY)
+ f.write(s)
+


Regards,

Kelly Anderson



More information about the systemd-devel mailing list