9from argparse
import ArgumentParser, RawTextHelpFormatter
10from pathlib
import Path
11from tempfile
import NamedTemporaryFile
17Generates the source files ui4.cpp, ui4.h used in the uic tool, the QtUiTools library and
18Qt Widgets Designer from the XML schema used for .ui files.
24opt_delete_temp_files =
True
28 """Read out the license from a C++ source"""
30 for line
in path.read_text().splitlines():
32 if 'SPDX-License-Identifier' in line:
38 """Replace special keys in XSL files and return a handle to temporary file"""
39 xsl = xsl_source_file.read_text()
40 xsl = xsl.replace(
"@LICENSE@", license)
42 xsl = xsl.replace(
"@HEADER@", ui_header_name)
44 result = NamedTemporaryFile(mode=
'w', suffix=
'.xsl',
46 delete=opt_delete_temp_files)
53 cmd = [
'xalan',
'-in', os.fspath(source),
'-xsl', os.fspath(sheet),
54 '-out', os.fspath(target)]
55 subprocess.check_call(cmd)
58if __name__ ==
'__main__':
59 argument_parser = ArgumentParser(description=DESCRIPTION,
60 formatter_class=RawTextHelpFormatter)
61 argument_parser.add_argument(
'--keep',
'-k', action=
'store_true',
62 help=
'Keep temporary files')
63 options = argument_parser.parse_args()
64 opt_delete_temp_files =
not options.keep
67 xml_dir = Path(__file__).parent.resolve()
68 ui4_xsd = xml_dir /
'ui4.xsd'
70 designer_dir = xml_dir.parent
71 uilib_dir = designer_dir /
"src" /
"lib" /
"uilib"
72 uilib_impl = uilib_dir /
'ui4.cpp'
75 print(
"Running XSLT processor for uilib header...\n")
76 header_xsl_source = xml_dir /
'generate_header.xsl'
78 run_xslt(ui4_xsd, header_xsl.name, uilib_dir /
'ui4_p.h')
80 print(
"Running XSLT processor for uilib source...\n")
81 impl_xsl_source = xml_dir /
'generate_impl.xsl'
83 run_xslt(ui4_xsd, impl_xsl.name, uilib_impl)
86 uic_dir = designer_dir.parents[2] /
"qtbase" /
"src" /
"tools" /
"uic"
87 uic_impl = uic_dir /
'ui4.cpp'
89 print(
"Running XSLT processor for uic header...\n")
91 run_xslt(ui4_xsd, header_xsl.name, uic_dir /
'ui4.h')
92 print(
"Running XSLT processor for uic source...\n")
94 run_xslt(ui4_xsd, impl_xsl.name, uic_impl)
96 subprocess.call([
'git',
'diff'])
replace_xsl_keys(xsl_source_file, license, ui_header_name=None)
run_xslt(source, sheet, target)
QDebug print(QDebug debug, QSslError::SslError error)