Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make update_version.py compatible with Python 3 #8555

Merged
merged 1 commit into from May 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions update_version.py
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'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more b' ' here.

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