Make language table generation script work with Python 3

It still works with Python 2 too for now.

See #23438.
This commit is contained in:
Vadim Zeitlin 2023-04-10 12:53:14 +02:00
parent be1fabcda3
commit b07a77cbf9

View file

@ -35,7 +35,7 @@ def ReadTable():
for i in f.readlines(): for i in f.readlines():
ispl = i.split() ispl = i.split()
table.append((ispl[0], ispl[1], ispl[2], ispl[3], ispl[4], ispl[5], ispl[6], string.join(ispl[7:]))) table.append((ispl[0], ispl[1], ispl[2], ispl[3], ispl[4], ispl[5], ispl[6], ' '.join(ispl[7:])))
f.close() f.close()
return table return table
@ -120,7 +120,7 @@ def WriteTable(f, table, scripttable):
elif (i[6] == "RTL"): elif (i[6] == "RTL"):
ilayout = "wxLayout_RightToLeft" ilayout = "wxLayout_RightToLeft"
else: else:
print "ERROR: Invalid value for the layout direction"; print("ERROR: Invalid value for the layout direction")
lngtable += ' { %-60s %-17s, %-28s, %-15s, %-4s, %-4s, %s, %s },\n' % \ lngtable += ' { %-60s %-17s, %-28s, %-15s, %-4s, %-4s, %s, %s },\n' % \
((i[0]+','), ibcp47, ican, icanbase, ilang, isublang, ilayout, i[7]) ((i[0]+','), ibcp47, ican, icanbase, ilang, isublang, ilayout, i[7])
@ -218,13 +218,13 @@ def ReplaceGeneratedPartOfFile(fname, func):
for l in fin.readlines(): for l in fin.readlines():
if l == '// --- --- --- generated code begins here --- --- ---\n': if l == '// --- --- --- generated code begins here --- --- ---\n':
if betweenBeginAndEnd or afterEnd: if betweenBeginAndEnd or afterEnd:
print 'Unexpected starting comment.' print('Unexpected starting comment.')
betweenBeginAndEnd = 1 betweenBeginAndEnd = 1
fout.write(l) fout.write(l)
func(fout, table, scripttable) func(fout, table, scripttable)
elif l == '// --- --- --- generated code ends here --- --- ---\n': elif l == '// --- --- --- generated code ends here --- --- ---\n':
if not betweenBeginAndEnd: if not betweenBeginAndEnd:
print 'End comment found before the starting one?' print('End comment found before the starting one?')
break break
betweenBeginAndEnd = 0 betweenBeginAndEnd = 0
@ -234,7 +234,7 @@ def ReplaceGeneratedPartOfFile(fname, func):
fout.write(l) fout.write(l)
if not afterEnd: if not afterEnd:
print 'Failed to process %s.' % fname print('Failed to process %s.' % fname)
os.remove(fnameNew) os.remove(fnameNew)
sys.exit(1) sys.exit(1)