This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[PATCH 2/3] overload.py: Fix python version 2/3 compatibility
- From: David Ward <david dot ward at ll dot mit dot edu>
- To: <systemtap at sourceware dot org>
- Date: Mon, 11 Feb 2019 12:25:38 -0500
- Subject: [PATCH 2/3] overload.py: Fix python version 2/3 compatibility
- References: <1549905939-4761-1-git-send-email-david.ward@ll.mit.edu>
The modified XML tree is outputted either as a bytearray with UTF-8
encoding in python version 3, or as a string in python version 2.
Handle this by writing the bytearray directly to sys.stdout.buffer,
or the string directly to sys.stdout, respectively.
Remove what appears to be "troubleshooting code" that was added in
commit 616ec7a0b, which dumps a large amount of unnecessary output
to stderr.
Call this script using the configured program name for python.
---
doc/SystemTap_Tapset_Reference/Makefile.am | 2 +-
doc/SystemTap_Tapset_Reference/Makefile.in | 2 +-
doc/SystemTap_Tapset_Reference/overload.py | 11 ++++-------
3 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/doc/SystemTap_Tapset_Reference/Makefile.am b/doc/SystemTap_Tapset_Reference/Makefile.am
index 8a91bd7..6599e52 100644
--- a/doc/SystemTap_Tapset_Reference/Makefile.am
+++ b/doc/SystemTap_Tapset_Reference/Makefile.am
@@ -23,7 +23,7 @@ tapsets.xml: docproc $(shell find $(SRCTREE)/tapset -name '*.stp')
if BUILD_HTMLDOCS
sed -e '/^!Syscalls/{r $(abs_srcdir)/syscalls.xmlpart' -e 'd}' $(abs_srcdir)/tapsets.tmpl > tapsets.tmpl.new
SRCTREE=$(SRCTREE) $(DOCPROC) doc tapsets.tmpl.new > tapsets.xml.new
- python $(srcdir)/overload.py tapsets.xml.new > tapsets.xml.new1
+ $(preferred_python) $(srcdir)/overload.py tapsets.xml.new > tapsets.xml.new1
xsltproc $(srcdir)/sort-tapsets.xslt tapsets.xml.new1 > tapsets.xml.new2
rm tapsets.xml.new tapsets.xml.new1 tapsets.tmpl.new
if test -s tapsets.xml && cmp tapsets.xml.new2 tapsets.xml >/dev/null ; then \
diff --git a/doc/SystemTap_Tapset_Reference/Makefile.in b/doc/SystemTap_Tapset_Reference/Makefile.in
index c441e73..2196b5e 100644
--- a/doc/SystemTap_Tapset_Reference/Makefile.in
+++ b/doc/SystemTap_Tapset_Reference/Makefile.in
@@ -620,7 +620,7 @@ uninstall-am:
@BUILD_REFDOCS_TRUE@tapsets.xml: docproc $(shell find $(SRCTREE)/tapset -name '*.stp')
@BUILD_HTMLDOCS_TRUE@@BUILD_REFDOCS_TRUE@ sed -e '/^!Syscalls/{r $(abs_srcdir)/syscalls.xmlpart' -e 'd}' $(abs_srcdir)/tapsets.tmpl > tapsets.tmpl.new
@BUILD_HTMLDOCS_TRUE@@BUILD_REFDOCS_TRUE@ SRCTREE=$(SRCTREE) $(DOCPROC) doc tapsets.tmpl.new > tapsets.xml.new
-@BUILD_HTMLDOCS_TRUE@@BUILD_REFDOCS_TRUE@ python $(srcdir)/overload.py tapsets.xml.new > tapsets.xml.new1
+@BUILD_HTMLDOCS_TRUE@@BUILD_REFDOCS_TRUE@ $(preferred_python) $(srcdir)/overload.py tapsets.xml.new > tapsets.xml.new1
@BUILD_HTMLDOCS_TRUE@@BUILD_REFDOCS_TRUE@ xsltproc $(srcdir)/sort-tapsets.xslt tapsets.xml.new1 > tapsets.xml.new2
@BUILD_HTMLDOCS_TRUE@@BUILD_REFDOCS_TRUE@ rm tapsets.xml.new tapsets.xml.new1 tapsets.tmpl.new
@BUILD_HTMLDOCS_TRUE@@BUILD_REFDOCS_TRUE@ if test -s tapsets.xml && cmp tapsets.xml.new2 tapsets.xml >/dev/null ; then \
diff --git a/doc/SystemTap_Tapset_Reference/overload.py b/doc/SystemTap_Tapset_Reference/overload.py
index 18d670b..6ddec43 100755
--- a/doc/SystemTap_Tapset_Reference/overload.py
+++ b/doc/SystemTap_Tapset_Reference/overload.py
@@ -1,4 +1,3 @@
-#! /usr/bin/python
# XML tree transformation for systemtap function overloading
# This script merges all overloaded tapset function entries
# into one entry.
@@ -45,7 +44,6 @@ def annotate(entry):
"""
Numbers all overloaded entries.
"""
- sys.stderr.write("entry: %s\n" % etree.tostring(entry))
num_overloads = len(entry.xpath("refsynopsisdiv/programlisting"))
synopsis = entry.xpath("refsynopsisdiv/programlisting")
description = entry.xpath("refsect1[2]/para")
@@ -59,8 +57,6 @@ def merge(functions):
"""
merged = functions[0]
- sys.stderr.write("processing item %s\n" % merged.xpath("refnamediv/refname")[0].text)
-
# merge params
new_params = get_params(functions)
param_list = merged.xpath("refsect1[1]/variablelist")[0]
@@ -84,7 +80,7 @@ def merge_overloads(functions_list):
merge(functions)
def usage():
- print "Usage: ./overload.py <xml>"
+ print("Usage: ./overload.py <xml>")
def main():
if len(sys.argv) != 2:
@@ -96,8 +92,9 @@ def main():
refentries = [r for r in root.iter("refentry")]
functions = collect_overloads(refentries)
merge_overloads(functions)
- print etree.tostring(root, encoding='UTF-8', xml_declaration=True,
- doctype=tree.docinfo.doctype)
+ output_file = getattr(sys.stdout, "buffer", sys.stdout)
+ tree.write(output_file, encoding="UTF-8", xml_declaration=True,
+ doctype=tree.docinfo.doctype)
if __name__ == '__main__':
main()
--
1.8.3.1