diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2017-06-08 12:30:22 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2017-06-09 08:24:40 +0000 |
commit | 6a4875f0d17f7ab282eebfd2870918a1abf032a5 (patch) | |
tree | 2fd71536784f1dd1fa08edf7db5bbba0511f8b9a /util/local_database/qlocalexml2cpp.py | |
parent | e93af7dafd4d45cfb48efb766080964f666b4f87 (diff) |
Replace three functions with one simpler function
load{Language,Script,Country}Map() were all structurally very similar,
so replace them with a single loadMap() that takes a second argument
to say *which* map to load. At the same time, use a dict
comprehension to simplify constructing the result.
Change-Id: Ie43a71156010277200543a8937056efd35251955
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'util/local_database/qlocalexml2cpp.py')
-rwxr-xr-x | util/local_database/qlocalexml2cpp.py | 44 |
1 files changed, 9 insertions, 35 deletions
diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index 42e0dbbf3c..44187ede59 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -88,38 +88,12 @@ def eltText(elt): child = child.nextSibling return result -def loadLanguageMap(doc): - result = {} - - for language_elt in eachEltInGroup(doc.documentElement, "languageList", "language"): - language_id = int(eltText(firstChildElt(language_elt, "id"))) - language_name = eltText(firstChildElt(language_elt, "name")) - language_code = eltText(firstChildElt(language_elt, "code")) - result[language_id] = (language_name, language_code) - - return result - -def loadScriptMap(doc): - result = {} - - for script_elt in eachEltInGroup(doc.documentElement, "scriptList", "script"): - script_id = int(eltText(firstChildElt(script_elt, "id"))) - script_name = eltText(firstChildElt(script_elt, "name")) - script_code = eltText(firstChildElt(script_elt, "code")) - result[script_id] = (script_name, script_code) - - return result - -def loadCountryMap(doc): - result = {} - - for country_elt in eachEltInGroup(doc.documentElement, "countryList", "country"): - country_id = int(eltText(firstChildElt(country_elt, "id"))) - country_name = eltText(firstChildElt(country_elt, "name")) - country_code = eltText(firstChildElt(country_elt, "code")) - result[country_id] = (country_name, country_code) - - return result +def loadMap(doc, category): + return dict((int(eltText(firstChildElt(element, 'id'))), + (eltText(firstChildElt(element, 'name')), + eltText(firstChildElt(element, 'code')))) + for element in eachEltInGroup(doc.documentElement, + category + 'List', category)) def loadLikelySubtagsMap(doc): result = {} @@ -391,9 +365,9 @@ def main(): data_temp_file.write(GENERATED_BLOCK_START) doc = xml.dom.minidom.parse(localexml) - language_map = loadLanguageMap(doc) - script_map = loadScriptMap(doc) - country_map = loadCountryMap(doc) + language_map = loadMap(doc, 'language') + script_map = loadMap(doc, 'script') + country_map = loadMap(doc, 'country') likely_subtags_map = loadLikelySubtagsMap(doc) default_map = {} for key in likely_subtags_map.keys(): |