Skip to content

Commit 17b0fb9

Browse files
authored
Make update_version.py compatible with Python 3 (#8555)
1 parent 4aa425c commit 17b0fb9

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Diff for: update_version.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@
1313
from xml.dom import minidom
1414

1515
if len(sys.argv) < 2 or len(sys.argv) > 3:
16-
print """
16+
print("""
1717
[ERROR] Please specify a version.
1818
1919
./update_version.py <MAJOR>.<MINOR>.<MICRO> [<RC version>]
2020
2121
Example:
2222
./update_version.py 3.7.1 2
23-
"""
23+
""")
2424
exit(1)
2525

2626
NEW_VERSION = sys.argv[1]
2727
NEW_VERSION_INFO = [int(x) for x in NEW_VERSION.split('.')]
2828
if len(NEW_VERSION_INFO) != 3:
29-
print """
29+
print("""
3030
[ERROR] Version must be in the format <MAJOR>.<MINOR>.<MICRO>
3131
3232
Example:
3333
./update_version.py 3.7.3
34-
"""
34+
""")
3535
exit(1)
3636

3737
RC_VERSION = -1
@@ -71,9 +71,9 @@ def RewriteXml(filename, rewriter, add_xml_prefix=True):
7171
content = document.toxml().replace('<?xml version="1.0" ?>', '')
7272
file_handle = open(filename, 'wb')
7373
if add_xml_prefix:
74-
file_handle.write('<?xml version="1.0" encoding="UTF-8"?>\n')
75-
file_handle.write(content)
76-
file_handle.write('\n')
74+
file_handle.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
75+
file_handle.write(content.encode('utf-8'))
76+
file_handle.write(b'\n')
7777
file_handle.close()
7878

7979

@@ -83,7 +83,7 @@ def RewriteTextFile(filename, line_rewriter):
8383
for line in lines:
8484
updated_lines.append(line_rewriter(line))
8585
if lines == updated_lines:
86-
print '%s was not updated. Please double check.' % filename
86+
print('%s was not updated. Please double check.' % filename)
8787
f = open(filename, 'w')
8888
f.write(''.join(updated_lines))
8989
f.close()
@@ -245,11 +245,11 @@ def UpdateMakefile():
245245
protobuf_version_offset = 11
246246
expected_major_version = 3
247247
if NEW_VERSION_INFO[0] != expected_major_version:
248-
print """[ERROR] Major protobuf version has changed. Please update
248+
print("""[ERROR] Major protobuf version has changed. Please update
249249
update_version.py to readjust the protobuf_version_offset and
250250
expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is
251251
always increasing.
252-
"""
252+
""")
253253
exit(1)
254254

255255
protobuf_version_info = '%d:%d:0' % (

0 commit comments

Comments
 (0)