Merge "Migrate java-event-logs-tags.py to python3."
This commit is contained in:
commit
6c38edc0b9
4 changed files with 33 additions and 32 deletions
|
@ -8,7 +8,7 @@ py_binary(
|
|||
srcs=["java-event-log-tags.py"],
|
||||
deps=[":event_log_tags"],
|
||||
visibility = ["//visibility:public"],
|
||||
python_version = "PY2",
|
||||
python_version = "PY3",
|
||||
)
|
||||
|
||||
py_binary(
|
||||
|
@ -16,5 +16,5 @@ py_binary(
|
|||
srcs=["merge-event-log-tags.py"],
|
||||
deps=[":event_log_tags"],
|
||||
visibility = ["//visibility:public"],
|
||||
python_version = "PY2",
|
||||
python_version = "PY3",
|
||||
)
|
||||
|
|
|
@ -55,12 +55,13 @@ class TagFile(object):
|
|||
if file_object is None:
|
||||
try:
|
||||
file_object = open(filename, "rb")
|
||||
except (IOError, OSError), e:
|
||||
except (IOError, OSError) as e:
|
||||
self.AddError(str(e))
|
||||
return
|
||||
|
||||
try:
|
||||
for self.linenum, line in enumerate(file_object):
|
||||
line = line.decode('utf-8')
|
||||
self.linenum += 1
|
||||
line = re.sub('#.*$', '', line) # strip trailing comments
|
||||
line = line.strip()
|
||||
|
@ -100,7 +101,7 @@ class TagFile(object):
|
|||
|
||||
self.tags.append(Tag(tag, tagname, description,
|
||||
self.filename, self.linenum))
|
||||
except (IOError, OSError), e:
|
||||
except (IOError, OSError) as e:
|
||||
self.AddError(str(e))
|
||||
|
||||
|
||||
|
@ -128,8 +129,8 @@ def WriteOutput(output_file, data):
|
|||
output_file = "<stdout>"
|
||||
else:
|
||||
out = open(output_file, "wb")
|
||||
out.write(data)
|
||||
out.write(str.encode(data))
|
||||
out.close()
|
||||
except (IOError, OSError), e:
|
||||
print >> sys.stderr, "failed to write %s: %s" % (output_file, e)
|
||||
except (IOError, OSError) as e:
|
||||
print("failed to write %s: %s" % (output_file, e), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (C) 2009 The Android Open Source Project
|
||||
#
|
||||
|
@ -23,7 +23,7 @@ tags in the given input file.
|
|||
-h to display this usage message and exit.
|
||||
"""
|
||||
|
||||
import cStringIO
|
||||
from io import StringIO
|
||||
import getopt
|
||||
import os
|
||||
import os.path
|
||||
|
@ -36,24 +36,24 @@ 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) != 1 and len(args) != 2:
|
||||
print "need one or two input files, not %d" % (len(args),)
|
||||
print __doc__
|
||||
print("need one or two input files, not %d" % (len(args),))
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
fn = args[0]
|
||||
|
@ -92,10 +92,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,))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (C) 2009 The Android Open Source Project
|
||||
#
|
||||
|
@ -24,7 +24,7 @@ and fails if they do.
|
|||
-h to display this usage message and exit.
|
||||
"""
|
||||
|
||||
import cStringIO
|
||||
from io import StringIO
|
||||
import getopt
|
||||
try:
|
||||
import hashlib
|
||||
|
@ -48,21 +48,21 @@ ASSIGN_LIMIT = 1000000
|
|||
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], "ho:m:")
|
||||
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
|
||||
elif o == "-m":
|
||||
pre_merged_file = a
|
||||
else:
|
||||
print >> sys.stderr, "unhandled option %s" % (o,)
|
||||
print("unhandled option %s" % (o,), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Restrictions on tags:
|
||||
|
@ -133,12 +133,12 @@ for fn in args:
|
|||
|
||||
if errors:
|
||||
for fn, ln, msg in 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)
|
||||
|
||||
if warnings:
|
||||
for fn, ln, msg in warnings:
|
||||
print >> sys.stderr, "%s:%d: warning: %s" % (fn, ln, msg)
|
||||
print("%s:%d: warning: %s" % (fn, ln, msg), file=sys.stderr)
|
||||
|
||||
# Python's hash function (a) isn't great and (b) varies between
|
||||
# versions of python. Using md5 is overkill here but is the same from
|
||||
|
@ -154,14 +154,14 @@ def hashname(str):
|
|||
# If we were provided pre-merged tags (w/ the -m option), then don't
|
||||
# ever try to allocate one, just fail if we don't have a number
|
||||
|
||||
for name, t in sorted(by_tagname.iteritems()):
|
||||
for name, t in sorted(by_tagname.items()):
|
||||
if t.tagnum is None:
|
||||
if pre_merged_tags:
|
||||
try:
|
||||
t.tagnum = pre_merged_tags[t.tagname]
|
||||
except KeyError:
|
||||
print >> sys.stderr, ("Error: Tag number not defined for tag `%s'."
|
||||
+" Have you done a full build?") % t.tagname
|
||||
print("Error: Tag number not defined for tag `%s'. Have you done a full build?" % t.tagname,
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
else:
|
||||
while True:
|
||||
|
@ -174,8 +174,8 @@ for name, t in sorted(by_tagname.iteritems()):
|
|||
|
||||
# by_tagnum should be complete now; we've assigned numbers to all tags.
|
||||
|
||||
buffer = cStringIO.StringIO()
|
||||
for n, t in sorted(by_tagnum.iteritems()):
|
||||
buffer = StringIO()
|
||||
for n, t in sorted(by_tagnum.items()):
|
||||
if t.description:
|
||||
buffer.write("%d %s %s\n" % (t.tagnum, t.tagname, t.description))
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue