Skip to content
Snippets Groups Projects
Commit a230365a authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Sébastien Blin
Browse files

misc: clean image resource generation python script

Conform to PEP8 and Qt6/QML (remove QtQuick module version).

GitLab: #749
Change-Id: Ibccc8023e6f622f039bcdb470f3cade34cc2be9e
parent eb543c34
No related branches found
No related tags found
No related merge requests found
...@@ -122,7 +122,7 @@ if(LIBJAMI_FOUND) ...@@ -122,7 +122,7 @@ if(LIBJAMI_FOUND)
endif() endif()
include(FindPython3) include(FindPython3)
find_package(Python3 COMPONENTS Interpreter) find_package(Python3 3.6 REQUIRED COMPONENTS Interpreter)
set(PYTHON_EXEC ${Python3_EXECUTABLE}) set(PYTHON_EXEC ${Python3_EXECUTABLE})
set(QML_RESOURCES ${APP_SRC_DIR}/resources.qrc) set(QML_RESOURCES ${APP_SRC_DIR}/resources.qrc)
...@@ -155,7 +155,7 @@ file(GLOB_RECURSE ...@@ -155,7 +155,7 @@ file(GLOB_RECURSE
RES_FILES CONFIGURE_DEPENDS RES_FILES CONFIGURE_DEPENDS
${PROJECT_SOURCE_DIR}/resources/*) ${PROJECT_SOURCE_DIR}/resources/*)
execute_process( execute_process(
COMMAND ${PYTHON_EXEC} ${SCRIPTS_DIR}/gen-resources.py COMMAND ${PYTHON_EXEC} ${SCRIPTS_DIR}/gen_resources_qrc.py
WORKING_DIRECTORY ${APP_SRC_DIR}) WORKING_DIRECTORY ${APP_SRC_DIR})
# library compatibility (boost, libnotify, etc.) # library compatibility (boost, libnotify, etc.)
......
...@@ -59,7 +59,7 @@ Then, you can build the project ...@@ -59,7 +59,7 @@ Then, you can build the project
git clone https://review.jami.net/jami-project git clone https://review.jami.net/jami-project
``` ```
Jami installer uses **python3**. If it's not installed, please install it: Jami installer uses **python3 (minimum v3.6)**. If it's not installed, please install it:
```bash ```bash
cd jami-project/ cd jami-project/
...@@ -157,13 +157,13 @@ Only 64-bit MSVC build can be compiled. ...@@ -157,13 +157,13 @@ Only 64-bit MSVC build can be compiled.
- Qt WebSockets - Qt WebSockets
- Qt WebView - Qt WebView
- Download [Visual Studio](https://visualstudio.microsoft.com/) (version == 2019). Note: version 2022 does not work. *See the SDK and Toolset notes below.* - Download [Visual Studio](https://visualstudio.microsoft.com/) (version == 2019). Note: version 2022 does not work. _See the SDK and Toolset notes below._
| | SDK | Toolset | MFC | | | SDK | Toolset | MFC |
| -------------------- | ------------ | ------- | --- | | ------------ | ------------ | ------- | ------ |
| Requirement: | 10.0.16299.0 | V142 | latest | | Requirement: | 10.0.16299.0 | V142 | latest |
- Install Qt Vs Tools under extensions, and configure msvc2017_64 path under Qt Options. *See the Qt notes below.* - Install Qt Vs Tools under extensions, and configure msvc2017_64 path under Qt Options. _See the Qt notes below._
| | Qt Version | | | Qt Version |
| -------------------- | ---------- | | -------------------- | ---------- |
...@@ -197,14 +197,14 @@ Only 64-bit MSVC build can be compiled. ...@@ -197,14 +197,14 @@ Only 64-bit MSVC build can be compiled.
``` ```
> **SDK and Toolset** Note: > **SDK and Toolset** Note:
Jami can be build with more rencents Windows SDK and Toolset than the ones specified in the table above. However, if your have another version than SDK 10.0.16299.0 and/or Toolset v142 installed, you need to identify it according to the example below. > Jami can be build with more rencents Windows SDK and Toolset than the ones specified in the table above. However, if your have another version than SDK 10.0.16299.0 and/or Toolset v142 installed, you need to identify it according to the example below.
```bash ```bash
python build.py --install --sdk <your-sdk-version> --toolset <your-toolset-version> python build.py --install --sdk <your-sdk-version> --toolset <your-toolset-version>
``` ```
> **Qt** Note: If you have another version than qt 6.2.3 installed this step will build daemon correctly but will fail for the client. > **Qt** Note: If you have another version than qt 6.2.3 installed this step will build daemon correctly but will fail for the client.
When that happens you need to compile the client separately: > When that happens you need to compile the client separately:
```bash ```bash
python build.py --install python build.py --install
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2021-2022 Savoir-faire Linux Inc. # Copyright (C) 2021-2022 Savoir-faire Linux Inc.
# #
# Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
# Author: Amin Bandali <amin.bandali@savoirfairelinux.com>
#
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or # the Free Software Foundation; either version 3 of the License, or
...@@ -15,10 +15,17 @@ ...@@ -15,10 +15,17 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA.
"""
Generate qrc file for generic resource files (images, text documents, etc.)
recursively within the resource directory. A QML file is also generated that
contains a property for each resource file, which can be accessed from QML via
a QML singleton.
"""
import os import os
import sys
import re import re
# These paths should be relative to the working directory of the # These paths should be relative to the working directory of the
...@@ -27,32 +34,44 @@ import re ...@@ -27,32 +34,44 @@ import re
resdir = os.path.join('..', '..', 'resources') resdir = os.path.join('..', '..', 'resources')
qmlfile = os.path.join('constant', 'JamiResources.qml') qmlfile = os.path.join('constant', 'JamiResources.qml')
resfile = os.path.join('resources.qrc') resfile = os.path.join('resources.qrc')
sep = '_'
print("Generating resource files ...") print("Generating resource.qrc file ...")
def format_qml_prop(prop):
"""
Replace characters that aren't valid within QML property names.
- replace all spaces, periods, and hyphens with underscores
- change all characters to lowercase
"""
return "".join([{".": "_", "-": "_", " ": "_"}
.get(c, c) for c in prop]
).lower()
# 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(resfile, 'w') as qrc, open(qmlfile, 'w') as qml: # Generate the the resources.qrc file and the JamiResources.qml file
# that will be used to access the resources.
with open(resfile, 'w', encoding='utf-8') as qrc, \
open(qmlfile, 'w', encoding='utf-8') as qml:
qrc.write('<RCC>\n') qrc.write('<RCC>\n')
qml.write('pragma Singleton\nimport QtQuick 2.14\nQtObject {\n') qml.write('pragma Singleton\nimport QtQuick\nQtObject {\n')
for root, _, files in os.walk(resdir): for root, _, files in os.walk(resdir):
if len(files): if len(files):
prefix = root.rsplit(os.sep, 1)[-1] prefix = root.rsplit(os.sep, 1)[-1]
qrc.write('\t<qresource prefix="/%s">\n' % prefix) # add a prefix to the resource file
qrc.write(f'\t<qresource prefix="/{prefix}">\n')
for filename in files: for filename in files:
# use posix separators in the resource path # use posix separators in the resource path
filepath = os.path.join(root, filename).replace(os.sep, '/') filepath = os.path.join(root, filename).replace(os.sep, '/')
qrc.write('\t\t<file alias="%s">%s</file>\n' qrc.write(f'\t\t<file alias="{filename}">{filepath}</file>\n')
% (filename, filepath))
# only record images/icons as properties # only record images/icons as properties
if (re.match("icons|images", prefix)): if re.match("icons|images", prefix):
qml.write(' readonly property string %s: "qrc:/%s"\n' resource = f'qrc:/{prefix}/{filename}'
% (formatProp(filename), filepath.split('/', 3)[-1])) qml.write(
" readonly property string"
f' {format_qml_prop(filename)}:'
f' "{resource}"\n'
)
qrc.write('\t</qresource>\n') qrc.write('\t</qresource>\n')
qml.write('}') qml.write('}')
qrc.write('</RCC>') qrc.write('</RCC>')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment