summaryrefslogtreecommitdiffstats
path: root/util/locale_database/cldr2qlocalexml.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/cldr2qlocalexml.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/cldr2qlocalexml.py')
-rwxr-xr-xutil/locale_database/cldr2qlocalexml.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/util/locale_database/cldr2qlocalexml.py b/util/locale_database/cldr2qlocalexml.py
index 28bf7ae641..d3aa88ec38 100755
--- a/util/locale_database/cldr2qlocalexml.py
+++ b/util/locale_database/cldr2qlocalexml.py
@@ -37,17 +37,25 @@ All the scripts mentioned support --help to tell you how to use them.
"""
from pathlib import Path
-import sys
import argparse
from cldr import CldrReader
from qlocalexml import QLocaleXmlWriter
-def main(out, err):
- all_calendars = ['gregorian', 'persian', 'islamic'] # 'hebrew'
+def main(argv, out, err):
+ """Generate a QLocaleXML file from CLDR data.
+
+ Takes sys.argv, sys.stdout, sys.stderr (or equivalents) as
+ arguments. In argv[1:], it expects the root of the CLDR data
+ directory as first parameter and the name of the file in which to
+ save QLocaleXML data as second parameter. It accepts a --calendars
+ option to select which calendars to support (all available by
+ default)."""
+ all_calendars = ['gregorian', 'persian', 'islamic']
parser = argparse.ArgumentParser(
+ prog=Path(argv[0]).name,
description='Generate QLocaleXML from CLDR data.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('cldr_path', help='path to the root of the CLDR tree')
@@ -57,7 +65,7 @@ def main(out, err):
nargs='+', metavar='CALENDAR',
choices=all_calendars, default=all_calendars)
- args = parser.parse_args()
+ args = parser.parse_args(argv[1:])
root = Path(args.cldr_path)
root_xml_path = 'common/main/root.xml'
@@ -90,4 +98,5 @@ def main(out, err):
return 0
if __name__ == '__main__':
- sys.exit(main(sys.stdout, sys.stderr))
+ import sys
+ sys.exit(main(sys.argv, sys.stdout, sys.stderr))