public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: David Ward <david.ward@ll.mit.edu>
To: <systemtap@sourceware.org>
Subject: [PATCH 2/3] overload.py: Fix python version 2/3 compatibility
Date: Mon, 11 Feb 2019 17:25:00 -0000	[thread overview]
Message-ID: <1549905939-4761-3-git-send-email-david.ward@ll.mit.edu> (raw)
In-Reply-To: <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

  parent reply	other threads:[~2019-02-11 17:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-11 17:25 [PATCH 0/3] Fix build issues involving Python David Ward
2019-02-11 17:25 ` [PATCH 1/3] configure: Fix handling of python versions 2 and 3 David Ward
2019-02-11 17:25 ` David Ward [this message]
2019-02-11 17:25 ` [PATCH 3/3] doc/Makefile: Fix command list syntax David Ward
2019-04-04 20:17 ` [PATCH 0/3] Fix build issues involving Python Serhei Makarov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1549905939-4761-3-git-send-email-david.ward@ll.mit.edu \
    --to=david.ward@ll.mit.edu \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).