Make update_version.py compatible with Python 3 (#8555)

pull/8561/head
Adam Cozzette 4 years ago committed by GitHub
parent 4aa425c6c5
commit 17b0fb9149
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      update_version.py

@ -13,25 +13,25 @@ import sys
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
@ -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()
@ -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()
@ -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' % (

Loading…
Cancel
Save