Commit 773a53bd authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

Improve Python 3 support in //base/win/embedded_i18n/create_string_rc.py

The script still works with Python 2.
There are no intended behaviour changes.

Bug: 941669
Change-Id: I3ec0bcaf05a6b388a9d47d123364ec27b6e927a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1559959
Auto-Submit: Raul Tambre <raul@tambre.ee>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Commit-Queue: Raul Tambre <raul@tambre.ee>
Cr-Commit-Position: refs/heads/master@{#649831}
parent cf65e7a9
...@@ -61,7 +61,6 @@ Note: MODE_SPECIFIC_STRINGS cannot be specified if STRING_IDS is not specified. ...@@ -61,7 +61,6 @@ Note: MODE_SPECIFIC_STRINGS cannot be specified if STRING_IDS is not specified.
from __future__ import print_function from __future__ import print_function
import argparse import argparse
import exceptions
import glob import glob
import io import io
import os import os
...@@ -273,20 +272,20 @@ class StringRcMaker(object): ...@@ -273,20 +272,20 @@ class StringRcMaker(object):
self.language = language self.language = language
self.translation = translation self.translation = translation
def __cmp__(self, other): def __lt__(self, other):
"""Allow __TranslationDatas to be sorted by id then by language.""" """Allow __TranslationDatas to be sorted by id then by language."""
id_result = cmp(self.resource_id_str, other.resource_id_str) return (self.resource_id_str, self.language) < (other.resource_id_str,
return cmp(self.language, other.language) if id_result == 0 else id_result other.language)
def __AddModeSpecificStringIds(self): def __AddModeSpecificStringIds(self):
"""Adds the mode-specific strings for all of the current brand's install """Adds the mode-specific strings for all of the current brand's install
modes to self.string_id_set.""" modes to self.string_id_set."""
for string_id, brands in self.mode_specific_strings.iteritems(): for string_id, brands in self.mode_specific_strings.items():
brand_strings = brands.get(self.brand) brand_strings = brands.get(self.brand)
if not brand_strings: if not brand_strings:
raise exceptions.RuntimeError( raise RuntimeError(
'No strings declared for brand \'%s\' in MODE_SPECIFIC_STRINGS for ' 'No strings declared for brand \'%s\' in MODE_SPECIFIC_STRINGS for '
'message %s' % (self.brand, string_id)) 'message %s' % (self.brand, string_id))
self.string_id_set.update(brand_strings) self.string_id_set.update(brand_strings)
def __ReadSourceAndTranslatedStrings(self): def __ReadSourceAndTranslatedStrings(self):
...@@ -359,7 +358,7 @@ Extra input files: ...@@ -359,7 +358,7 @@ Extra input files:
# Manually put the source strings as en-US in the list of translated # Manually put the source strings as en-US in the list of translated
# strings. # strings.
translated_strings = [] translated_strings = []
for string_id, message_text in source_strings.iteritems(): for string_id, message_text in source_strings.items():
translated_strings.append(self.__TranslationData(string_id, translated_strings.append(self.__TranslationData(string_id,
'EN_US', 'EN_US',
message_text)) message_text))
...@@ -369,7 +368,7 @@ Extra input files: ...@@ -369,7 +368,7 @@ Extra input files:
# message text; hence the message id is mapped to a list of string ids # message text; hence the message id is mapped to a list of string ids
# instead of a single value. # instead of a single value.
translation_ids = {} translation_ids = {}
for (string_id, message_text) in source_strings.iteritems(): for (string_id, message_text) in source_strings.items():
message_id = tclib.GenerateMessageId(message_text) message_id = tclib.GenerateMessageId(message_text)
translation_ids.setdefault(message_id, []).append(string_id); translation_ids.setdefault(message_id, []).append(string_id);
...@@ -384,7 +383,7 @@ Extra input files: ...@@ -384,7 +383,7 @@ Extra input files:
if not xtb_filename in source_xtb_files: if not xtb_filename in source_xtb_files:
extra_xtb_files.append(xtb_filename) extra_xtb_files.append(xtb_filename)
sax_parser.parse(xtb_filename) sax_parser.parse(xtb_filename)
for string_id, message_text in source_strings.iteritems(): for string_id, message_text in source_strings.items():
translated_string = xtb_handler.translations.get(string_id, translated_string = xtb_handler.translations.get(string_id,
message_text) message_text)
translated_strings.append(self.__TranslationData(string_id, translated_strings.append(self.__TranslationData(string_id,
...@@ -464,13 +463,13 @@ Extra input files: ...@@ -464,13 +463,13 @@ Extra input files:
resource_id += 1 resource_id += 1
# Handle mode-specific strings. # Handle mode-specific strings.
for string_id, brands in self.mode_specific_strings.iteritems(): for string_id, brands in self.mode_specific_strings.items():
# Populate the DO_MODE_STRINGS macro. # Populate the DO_MODE_STRINGS macro.
brand_strings = brands.get(self.brand) brand_strings = brands.get(self.brand)
if not brand_strings: if not brand_strings:
raise exceptions.RuntimeError( raise RuntimeError(
'No strings declared for brand \'%s\' in MODE_SPECIFIC_STRINGS for ' 'No strings declared for brand \'%s\' in MODE_SPECIFIC_STRINGS for '
'message %s' % (self.brand, string_id)) 'message %s' % (self.brand, string_id))
do_mode_strings_lines.append( do_mode_strings_lines.append(
' HANDLE_MODE_STRING(%s_BASE, %s)' ' HANDLE_MODE_STRING(%s_BASE, %s)'
% (string_id, ', '.join([ ('%s_BASE' % s) for s in brand_strings]))) % (string_id, ', '.join([ ('%s_BASE' % s) for s in brand_strings])))
...@@ -490,7 +489,7 @@ Extra input files: ...@@ -490,7 +489,7 @@ Extra input files:
installer_string_mapping_lines.append(' HANDLE_STRING(%s_BASE, %s)' installer_string_mapping_lines.append(' HANDLE_STRING(%s_BASE, %s)'
% (string_id, string_id)) % (string_id, string_id))
with open(self.header_file, 'wb') as outfile: with open(self.header_file, 'w') as outfile:
outfile.write('\n'.join(lines)) outfile.write('\n'.join(lines))
outfile.write('\n#ifndef RC_INVOKED') outfile.write('\n#ifndef RC_INVOKED')
outfile.write(' \\\n'.join(do_languages_lines)) outfile.write(' \\\n'.join(do_languages_lines))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment