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 lines = path.read_text().splitlines()
31 for i
in range(len(lines)):
32 result += lines[i] +
"\n"
33 if 'Qt-Security' in lines[i]:
35 if 'SPDX-License-Identifier' in lines[i]
and not 'Qt-Security' in lines[i+1]:
41 """Replace special keys in XSL files and return a handle to temporary file"""
42 xsl = xsl_source_file.read_text()
43 xsl = xsl.replace(
"@LICENSE@", license)
45 xsl = xsl.replace(
"@HEADER@", ui_header_name)
47 result = NamedTemporaryFile(mode=
'w', suffix=
'.xsl',
49 delete=opt_delete_temp_files)
56 cmd = [
'xalan',
'-in', os.fspath(source),
'-xsl', os.fspath(sheet),
57 '-out', os.fspath(target)]
58 subprocess.check_call(cmd)
61if __name__ ==
'__main__':
62 argument_parser = ArgumentParser(description=DESCRIPTION,
63 formatter_class=RawTextHelpFormatter)
64 argument_parser.add_argument(
'--keep',
'-k', action=
'store_true',
65 help=
'Keep temporary files')
66 options = argument_parser.parse_args()
67 opt_delete_temp_files =
not options.keep
70 xml_dir = Path(__file__).parent.resolve()
71 ui4_xsd = xml_dir /
'ui4.xsd'
73 designer_dir = xml_dir.parent
74 uilib_dir = designer_dir /
"src" /
"lib" /
"uilib"
75 uilib_impl = uilib_dir /
'ui4.cpp'
78 print(
"Running XSLT processor for uilib header...\n")
79 header_xsl_source = xml_dir /
'generate_header.xsl'
81 run_xslt(ui4_xsd, header_xsl.name, uilib_dir /
'ui4_p.h')
83 print(
"Running XSLT processor for uilib source...\n")
84 impl_xsl_source = xml_dir /
'generate_impl.xsl'
86 run_xslt(ui4_xsd, impl_xsl.name, uilib_impl)
89 uic_dir = designer_dir.parents[2] /
"qtbase" /
"src" /
"tools" /
"uic"
90 uic_impl = uic_dir /
'ui4.cpp'
92 print(
"Running XSLT processor for uic header...\n")
94 run_xslt(ui4_xsd, header_xsl.name, uic_dir /
'ui4.h')
95 print(
"Running XSLT processor for uic source...\n")
97 run_xslt(ui4_xsd, impl_xsl.name, uic_impl)
99 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)