summaryrefslogtreecommitdiffstats
path: root/util/locale_database/qlocalexml2cpp.py
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2024-03-07 18:04:46 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2024-04-26 07:36:16 +0200
commitf83206229e246c3e9ccd1ea2a64b0e003b2cdbc5 (patch)
treed18ad74636ac0f6d009c70473dc0d84ecffc40a4 /util/locale_database/qlocalexml2cpp.py
parent165f638783a057ec376c60a124e779dcbe833201 (diff)
Apply a common style to the main()s of locale database programs
Include documentation in both, using common phrasing. Take sys.argv as a parameter, along with sys.stdout and sys.stderr, so that we can invoke them from python when importing into a python session to debug or test. Supply the script name to the argument parser as prog, so it can correctly report it and forward the rest of argv to parse_args(). Remove comments anticipating one of the several calendars we don't yet support; the existing entries suffice to make clear what shall be needed when we get round to adding more. Change-Id: I2cebd385679e3c84d4ccf899e60091ac823ad10d Reviewed-by: Mate Barany <mate.barany@qt.io>
Diffstat (limited to 'util/locale_database/qlocalexml2cpp.py')
-rwxr-xr-xutil/locale_database/qlocalexml2cpp.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/util/locale_database/qlocalexml2cpp.py b/util/locale_database/qlocalexml2cpp.py
index dcf1f04628..b20e4fd155 100755
--- a/util/locale_database/qlocalexml2cpp.py
+++ b/util/locale_database/qlocalexml2cpp.py
@@ -521,17 +521,29 @@ class LocaleHeaderWriter (SourceFileEditor):
out('\n };\n')
-def main(out, err):
+def main(argv, out, err):
+ """Updates QLocale's CLDR data from a QLocaleXML file.
+
+ Takes sys.argv, sys.stdout, sys.stderr (or equivalents) as
+ arguments. In argv[1:] it expects the QLocaleXML file as first
+ parameter and the ISO 639-3 data table as second
+ parameter. Accepts the root of the qtbase checkout as third
+ parameter (default is inferred from this script's path) and a
+ --calendars option to select which calendars to support (all
+ available by default).
+
+ Updates various src/corelib/t*/q*_data_p.h files within the qtbase
+ checkout to contain data extracted from the QLocaleXML file."""
calendars_map = {
# CLDR name: Qt file name fragment
'gregorian': 'roman',
'persian': 'jalali',
'islamic': 'hijri',
- # 'hebrew': 'hebrew'
}
all_calendars = list(calendars_map.keys())
parser = argparse.ArgumentParser(
+ prog=Path(argv[0]).name,
description='Generate C++ code from CLDR data in QLocaleXML form.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('input_file', help='input XML file name',
@@ -543,7 +555,7 @@ def main(out, err):
parser.add_argument('--calendars', help='select calendars to emit data for',
nargs='+', metavar='CALENDAR',
choices=all_calendars, default=all_calendars)
- args = parser.parse_args()
+ args = parser.parse_args(argv[1:])
qlocalexml = args.input_file
qtsrcdir = Path(args.qtbase_path)
@@ -624,4 +636,4 @@ def main(out, err):
if __name__ == "__main__":
import sys
- sys.exit(main(sys.stdout, sys.stderr))
+ sys.exit(main(sys.argv, sys.stdout, sys.stderr))