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>
This commit is contained in:
parent
165f638783
commit
f83206229e
@ -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))
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user