LocaleDB: Make passing qtbase root dir on command-lines optional

We can easily enough obtain the root of the present source tree using
the value of __file__, so might as well do so.

Change-Id: If14773ac1127278b6018a090c0b376437b9c6eec
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
This commit is contained in:
Edward Welbourne 2022-10-17 10:58:31 +02:00
parent b77da049bc
commit 0de7e7a066
3 changed files with 21 additions and 13 deletions

View File

@ -4,11 +4,12 @@
"""Parse CLDR data for QTimeZone use with MS-Windows
Script to parse the CLDR common/supplemental/windowsZones.xml file and
encode for use in QTimeZone. See ``./cldr2qlocalexml.py`` for where
to get the CLDR data. Pass its root directory as first parameter to
this script and the qtbase root directory as second parameter. It
shall update qtbase's src/corelib/time/qtimezoneprivate_data_p.h ready
for use.
prepare its data for use in QTimeZone. See ``./cldr2qlocalexml.py`` for
where to get the CLDR data. Pass its root directory as first parameter
to this script. You can optionally pass the qtbase root directory as
second parameter; it defaults to the root of the checkout containing
this script. This script updates qtbase's
src/corelib/time/qtimezoneprivate_data_p.h with the new data.
"""
import datetime
@ -16,7 +17,7 @@ from pathlib import Path
import textwrap
import argparse
from localetools import unicode2hex, wrap_list, Error, SourceFileEditor
from localetools import unicode2hex, wrap_list, Error, SourceFileEditor, qtbase_root
from cldr import CldrAccess
### Data that may need updates in response to new entries in the CLDR file ###
@ -310,7 +311,9 @@ def main(out, err):
parser = argparse.ArgumentParser(
description="Update Qt's CLDR-derived timezone data.")
parser.add_argument('cldr_path', help='path to the root of the CLDR tree')
parser.add_argument('qtbase_path', help='path to the root of the qtbase source tree')
parser.add_argument('qtbase_path',
help='path to the root of the qtbase source tree',
nargs='?', default=qtbase_root)
args = parser.parse_args()

View File

@ -16,6 +16,9 @@ from contextlib import ExitStack, contextmanager
from pathlib import Path
from tempfile import NamedTemporaryFile
qtbase_root = Path(__file__).parents[2]
assert qtbase_root.name == 'qtbase'
class Error (Exception):
def __init__(self, msg, *args):
super().__init__(msg, *args)

View File

@ -4,9 +4,10 @@
"""Script to generate C++ code from CLDR data in QLocaleXML form
See ``cldr2qlocalexml.py`` for how to generate the QLocaleXML data itself.
Pass the output file from that as first parameter to this script; pass
the ISO 639-3 data file as second parameter; pass the root of the qtbase
check-out as third parameter.
Pass the output file from that as first parameter to this script; pass the ISO
639-3 data file as second parameter. You can optionally pass the root of the
qtbase check-out as third parameter; it defaults to the root of the qtbase
check-out containing this script.
The ISO 639-3 data file can be downloaded from the SIL website:
@ -19,7 +20,7 @@ from pathlib import Path
from typing import Optional
from qlocalexml import QLocaleXmlReader
from localetools import unicode2hex, wrap_list, Error, Transcriber, SourceFileEditor
from localetools import unicode2hex, wrap_list, Error, Transcriber, SourceFileEditor, qtbase_root
from iso639_3 import LanguageCodeData
class LocaleKeySorter:
@ -521,8 +522,8 @@ class LocaleHeaderWriter (SourceFileEditor):
def main(out, err):
# map { CLDR name: Qt file name }
calendars_map = {
# CLDR name: Qt file name fragment
'gregorian': 'roman',
'persian': 'jalali',
'islamic': 'hijri',
@ -537,7 +538,8 @@ def main(out, err):
metavar='input-file.xml')
parser.add_argument('iso_path', help='path to the ISO 639-3 data file',
metavar='iso-639-3.tab')
parser.add_argument('qtbase_path', help='path to the root of the qtbase source tree')
parser.add_argument('qtbase_path', help='path to the root of the qtbase source tree',
nargs='?', default=qtbase_root)
parser.add_argument('--calendars', help='select calendars to emit data for',
nargs='+', metavar='CALENDAR',
choices=all_calendars, default=all_calendars)