OSDN Git Service

py3: java-event-log-tags
authorAnthony King <anthonydking@slimroms.net>
Sat, 31 Oct 2015 19:25:51 +0000 (15:25 -0400)
committerSteve Kondik <steve@cyngn.com>
Sun, 4 Sep 2016 04:47:36 +0000 (21:47 -0700)
Change-Id: I0bf4cbe990c21b6d57e54e96ea62c56ca2d41b86

tools/java-event-log-tags.py

index f364751..6ac69bd 100755 (executable)
@@ -23,37 +23,43 @@ tags in the given input file.
 -h to display this usage message and exit.
 """
 
-import cStringIO
+from __future__ import print_function
+
 import getopt
 import os
 import os.path
 import re
 import sys
 
+try:
+  from cStringIO import StringIO
+except ImportError:
+  from io import StringIO
+
 import event_log_tags
 
 output_file = None
 
 try:
   opts, args = getopt.getopt(sys.argv[1:], "ho:")
-except getopt.GetoptError, err:
-  print str(err)
-  print __doc__
+except getopt.GetoptError as err:
+  print(str(err))
+  print(__doc__)
   sys.exit(2)
 
 for o, a in opts:
   if o == "-h":
-    print __doc__
+    print(__doc__)
     sys.exit(2)
   elif o == "-o":
     output_file = a
   else:
-    print >> sys.stderr, "unhandled option %s" % (o,)
+    print("unhandled option %s" % o, file=sys.stderr)
     sys.exit(1)
 
 if len(args) != 2:
-  print "need exactly two input files, not %d" % (len(args),)
-  print __doc__
+  print("need exactly two input files, not %d" % len(args))
+  print(__doc__)
   sys.exit(1)
 
 fn = args[0]
@@ -85,10 +91,10 @@ if "javadoc_hide" in tagfile.options:
 
 if tagfile.errors:
   for fn, ln, msg in tagfile.errors:
-    print >> sys.stderr, "%s:%d: error: %s" % (fn, ln, msg)
+    print("%s:%d: error: %s" % (fn, ln, msg), file=sys.stderr)
   sys.exit(1)
 
-buffer = cStringIO.StringIO()
+buffer = StringIO()
 buffer.write("/* This file is auto-generated.  DO NOT MODIFY.\n"
              " * Source file: %s\n"
              " */\n\n" % (fn,))