Scripts: Fix output for python 3

Change-Id: Ie914e04b25bdd4e41a9d2b3a9002385f5867ad6b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Stenger
2022-02-03 07:59:33 +01:00
parent 0d812cd59b
commit 394bfb508f

View File

@@ -181,6 +181,15 @@ def diffContext(ctx, old, new):
return report
def stringify(obj):
stringTypes = (str, unicode) if sys.version_info.major == 2 else (str)
if isinstance(obj, stringTypes):
return obj
if isinstance(obj, bytes):
tmp = obj.decode('cp1252') if platform.system() in ('Microsoft','Windows') else obj.decode()
return tmp
# --- The main program
oldGenerator = Generator()
@@ -203,21 +212,21 @@ newContextSet = set(newTree.keys())
for c in sorted(oldContextSet.difference(newContextSet)):
report = diffContext(c, oldTree[c], {})
if report:
print(report.encode('utf-8'))
print(stringify(report.encode('utf-8')))
else:
unchangedContexts += 1
for c in sorted(newContextSet.difference(oldContextSet)):
report = diffContext(c, {}, newTree[c])
if report:
print(report.encode('utf-8'))
print(stringify(report.encode('utf-8')))
else:
unchangedContexts += 1
for c in sorted(newContextSet.intersection(oldContextSet)):
report = diffContext(c, oldTree[c], newTree[c])
if report:
print(report.encode('utf-8'))
print(stringify(report.encode('utf-8')))
else:
unchangedContexts += 1