Skip to content

Commit

Permalink
Make update_version.py compatible with Python 3 (#8555)
Browse files Browse the repository at this point in the history
  • Loading branch information
acozzette authored May 3, 2021
1 parent 4aa425c commit 17b0fb9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
from xml.dom import minidom

if len(sys.argv) < 2 or len(sys.argv) > 3:
print """
print("""
[ERROR] Please specify a version.
./update_version.py <MAJOR>.<MINOR>.<MICRO> [<RC version>]
Example:
./update_version.py 3.7.1 2
"""
""")
exit(1)

NEW_VERSION = sys.argv[1]
NEW_VERSION_INFO = [int(x) for x in NEW_VERSION.split('.')]
if len(NEW_VERSION_INFO) != 3:
print """
print("""
[ERROR] Version must be in the format <MAJOR>.<MINOR>.<MICRO>
Example:
./update_version.py 3.7.3
"""
""")
exit(1)

RC_VERSION = -1
Expand Down Expand Up @@ -71,9 +71,9 @@ def RewriteXml(filename, rewriter, add_xml_prefix=True):
content = document.toxml().replace('<?xml version="1.0" ?>', '')
file_handle = open(filename, 'wb')
if add_xml_prefix:
file_handle.write('<?xml version="1.0" encoding="UTF-8"?>\n')
file_handle.write(content)
file_handle.write('\n')
file_handle.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
file_handle.write(content.encode('utf-8'))
file_handle.write(b'\n')
file_handle.close()


Expand All @@ -83,7 +83,7 @@ def RewriteTextFile(filename, line_rewriter):
for line in lines:
updated_lines.append(line_rewriter(line))
if lines == updated_lines:
print '%s was not updated. Please double check.' % filename
print('%s was not updated. Please double check.' % filename)
f = open(filename, 'w')
f.write(''.join(updated_lines))
f.close()
Expand Down Expand Up @@ -245,11 +245,11 @@ def UpdateMakefile():
protobuf_version_offset = 11
expected_major_version = 3
if NEW_VERSION_INFO[0] != expected_major_version:
print """[ERROR] Major protobuf version has changed. Please update
print("""[ERROR] Major protobuf version has changed. Please update
update_version.py to readjust the protobuf_version_offset and
expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is
always increasing.
"""
""")
exit(1)

protobuf_version_info = '%d:%d:0' % (
Expand Down

0 comments on commit 17b0fb9

Please sign in to comment.