Ensure we use UTF-8 for the emitted QLocaleXML data file

Python helpfully uses a sensible locale when stdout is a tty but uses
the system (not the filesystem) default encoding, which may be ascii
and unable to encode some of the data we need to save. So brute force
kludge it to ensure emit.encoding is UTF-8 when writing the output
we'll read as UTF-8 anyway.

(This matches dev's commit 0ef79d94f6dcf276ca55b084d27f980b1f260473
for the reworked version of the script.)

Task-number: QTBUG-79902
Change-Id: I60ddc896a308c06e01fa87e8e18e112faa17d601
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
This commit is contained in:
Edward Welbourne 2020-03-17 17:39:43 +01:00
parent 67c0e28789
commit cabd8f860b

View File

@ -55,6 +55,7 @@ time zone names; see cldr2qtimezone.py for details.
"""
import os
import sys
from localetools import Error
from cldr import CldrReader
@ -101,6 +102,10 @@ def main(args, out, err):
usage(name, err, 'Too many arguments - excess: ' + ' '.join(args))
return 1
if emit.encoding != 'UTF-8' or (emit.encoding is None and sys.getdefaultencoding() != 'UTF-8'):
reload(sys) # Weirdly, this gets a richer sys module than the plain import got us !
sys.setdefaultencoding('UTF-8')
# TODO - command line options to tune choice of grumble and whitter:
reader = CldrReader(root, err.write, err.write)
writer = QLocaleXmlWriter(emit.write)
@ -114,5 +119,4 @@ def main(args, out, err):
return 0
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv, sys.stdout, sys.stderr))