1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2024-10-28 16:59:36 +01:00
jami-client-qt/gen-resources.py
Amin Bandali c7fdf3ff30 misc: move application sources from 'src/' to 'src/app/'
In preparation for vendoring libjamiclient into 'src/libclient/'.

GitLab: #734
Change-Id: Ibd956abc8fe9bd454ac0e9a5a28b77a5a74174e7
2022-05-19 15:47:30 -04:00

35 lines
1.3 KiB
Python

import os
import sys
import re
resdir = 'resources'
qmlfile = os.path.join('src', 'app', 'constant', 'JamiResources.qml')
sep = '_'
print("Generating resource files ...")
# replace characters that aren't valid within QML property names
formatProp = lambda str: (
"".join([{".": sep, "-": sep, " ": sep}
.get(c, c) for c in str]
).lower())
with open('resources.qrc', 'w') as qrc, open(qmlfile, 'w') as qml:
qrc.write('<RCC>\n')
qml.write('pragma Singleton\nimport QtQuick 2.14\nQtObject {\n')
for root, _, files in os.walk(resdir):
if len(files):
prefix = root.rsplit(os.sep, 1)[-1]
qrc.write('\t<qresource prefix="/%s">\n' % prefix)
for filename in files:
# use posix separators in the resource path
filepath = os.path.join(root, filename).replace(os.sep, '/')
qrc.write('\t\t<file alias="%s">%s</file>\n'
% (filename, filepath))
# only record images/icons as properties
if (re.match("icons|images", prefix)):
qml.write(' readonly property string %s: "qrc:/%s"\n'
% (formatProp(filename), filepath.split('/', 1)[1]))
qrc.write('\t</qresource>\n')
qml.write('}')
qrc.write('</RCC>')