Add --verbose and --quiet arguments to CLDR processing commands

Support control over verbosity of output. For now just have
qlocalexml2cpp.py show a stack-trace when failing (and return on all
failures) and have cldr2qlocalexml.py route its information to stdout
(when not in use as the XML output stream, else stderr) or discard it
in quiet mode.

Change-Id: I58afd3a083794eae3a35f6e1235bd62c288fabcf
Reviewed-by: Mate Barany <mate.barany@qt.io>
This commit is contained in:
Edward Welbourne 2024-04-30 16:18:32 +02:00
parent 70e2fe2bba
commit 97f50aee9d
2 changed files with 28 additions and 3 deletions

View File

@ -62,7 +62,10 @@ def main(argv, out, err):
parser.add_argument('--calendars', help='select calendars to emit data for',
nargs='+', metavar='CALENDAR',
choices=all_calendars, default=all_calendars)
parser.add_argument('-v', '--verbose', help='more verbose output',
action='count', default=0)
parser.add_argument('-q', '--quiet', help='less output',
dest='verbose', action='store_const', const=-1)
args = parser.parse_args(argv[1:])
root = Path(args.cldr_path)
@ -83,8 +86,11 @@ def main(argv, out, err):
except IOError as e:
parser.error(f'Failed to open "{xml}" to write output to it')
# TODO - command line options to tune choice of grumble and whitter:
reader = CldrReader(root, err.write, err.write)
reader = CldrReader(root,
(lambda *x: None) if args.verbose < 0 else
# Use stderr for logging if stdout is where our XML is going:
err.write if out is emit else out.write,
err.write)
writer = QLocaleXmlWriter(emit.write)
writer.version(reader.root.cldrVersion)

View File

@ -684,6 +684,10 @@ def main(argv, out, err):
parser.add_argument('--calendars', help='select calendars to emit data for',
nargs='+', metavar='CALENDAR',
choices=all_calendars, default=all_calendars)
parser.add_argument('-v', '--verbose', help='more verbose output',
action='count', default=0)
parser.add_argument('-q', '--quiet', help='less output',
dest='verbose', action='store_const', const=-1)
args = parser.parse_args(argv[1:])
qlocalexml = args.input_file
@ -717,6 +721,8 @@ def main(argv, out, err):
writer.territoryCodes(reader.territories)
except Exception as e:
err.write(f'\nError updating locale data: {e}\n')
if args.verbose > 0:
raise
return 1
# Generate calendar data
@ -728,6 +734,9 @@ def main(argv, out, err):
writer.write(calendar, locale_map, locale_keys)
except Exception as e:
err.write(f'\nError updating {calendar} locale data: {e}\n')
if args.verbose > 0:
raise
return 1
# qlocale.h
try:
@ -738,6 +747,9 @@ def main(argv, out, err):
writer.territories(reader.territories)
except Exception as e:
err.write(f'\nError updating qlocale.h: {e}\n')
if args.verbose > 0:
raise
return 1
# qlocale.qdoc
try:
@ -750,6 +762,8 @@ def main(argv, out, err):
qdoc.writer.write(line)
except Exception as e:
err.write(f'\nError updating qlocale.h: {e}\n')
if args.verbose > 0:
raise
return 1
# Locale-independent timezone data
@ -764,6 +778,8 @@ def main(argv, out, err):
writer.writeTables()
except Exception as e:
err.write(f'\nError updating qtimezoneprivate_data_p.h: {e}\n')
if args.verbose > 0:
raise
return 1
# ./testlocales/localemodel.cpp
@ -774,6 +790,9 @@ def main(argv, out, err):
test.localeList(locale_keys)
except Exception as e:
err.write(f'\nError updating localemodel.cpp: {e}\n')
if args.verbose > 0:
raise
return 1
return 0