[ovs-dev,21/55] xml2nroff: Make compatible with Python 3.
diff mbox

Message ID 1450730875-18083-22-git-send-email-russell@ovn.org
State Deferred
Headers show

Commit Message

Russell Bryant Dec. 21, 2015, 8:47 p.m. UTC
Update xml2nroff to work with either Python 2 or Python 3.  The changes
are minor and can be managed without the use of the six library.

For iterating a dict, we now use:

    for k, v in subst.items():

This is the same as .iteritems() in Python 2.  It's technically a little
less efficient for Python 2, as items() returns a list instead of an
iterator in Python 2.  We're dealing with a very small set of items here
so it really doesn't matter.

Signed-off-by: Russell Bryant <russell@ovn.org>
---
 build-aux/xml2nroff | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Patch
diff mbox

diff --git a/build-aux/xml2nroff b/build-aux/xml2nroff
index 00ef649..a4f8fbc 100755
--- a/build-aux/xml2nroff
+++ b/build-aux/xml2nroff
@@ -14,6 +14,8 @@ 
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import print_function
+
 import getopt
 import sys
 import xml.dom.minidom
@@ -24,7 +26,7 @@  argv0 = sys.argv[0]
 
 
 def usage():
-    print """\
+    print("""\
 %(argv0)s: XML to nroff converter
 Converts the XML format supplied as input into an nroff-formatted manpage.
 usage: %(argv0)s [OPTIONS] INPUT.XML [VAR=VALUE]...
@@ -36,14 +38,14 @@  corresponding VALUE, with characters &<>"' in VALUE escaped.
 The following options are also available:
   --version=VERSION           use VERSION to display on document footer
   -h, --help                  display this help message\
-""" % {'argv0': argv0}
+""" % {'argv0': argv0})
     sys.exit(0)
 
 
 def manpage_to_nroff(xml_file, subst, version=None):
     with open(xml_file) as f:
         content = f.read()
-    for k, v in subst.iteritems():
+    for k, v in subst.items():
         content = content.replace(k, v)
     doc = xml.dom.minidom.parseString(content).documentElement
 
@@ -82,7 +84,7 @@  if __name__ == "__main__":
     try:
         options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
                                           ['version=', 'help'])
-    except getopt.GetoptError, geo:
+    except getopt.GetoptError as geo:
         sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
         sys.exit(1)
 
@@ -114,13 +116,13 @@  if __name__ == "__main__":
 
     try:
         s = manpage_to_nroff(args[0], subst, version)
-    except build.nroff.error.Error, e:
+    except build.nroff.error.Error as e:
         sys.stderr.write("%s: %s\n" % (argv0, e.msg))
         sys.exit(1)
     for line in s.splitlines():
         line = line.strip()
         if line:
-            print line
+            print(line)
 
 
 # Local variables: