From a230365a9279b5f725c0d0d3675bad841efab5d5 Mon Sep 17 00:00:00 2001 From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> Date: Fri, 4 Nov 2022 17:18:22 -0400 Subject: [PATCH] misc: clean image resource generation python script Conform to PEP8 and Qt6/QML (remove QtQuick module version). GitLab: #749 Change-Id: Ibccc8023e6f622f039bcdb470f3cade34cc2be9e --- CMakeLists.txt | 4 +- INSTALL.md | 14 ++--- ...{gen-resources.py => gen_resources_qrc.py} | 59 ++++++++++++------- 3 files changed, 48 insertions(+), 29 deletions(-) rename extras/scripts/{gen-resources.py => gen_resources_qrc.py} (50%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a09fd6c4..d5c6f3e05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,7 +122,7 @@ if(LIBJAMI_FOUND) endif() include(FindPython3) -find_package(Python3 COMPONENTS Interpreter) +find_package(Python3 3.6 REQUIRED COMPONENTS Interpreter) set(PYTHON_EXEC ${Python3_EXECUTABLE}) set(QML_RESOURCES ${APP_SRC_DIR}/resources.qrc) @@ -155,7 +155,7 @@ file(GLOB_RECURSE RES_FILES CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/resources/*) execute_process( - COMMAND ${PYTHON_EXEC} ${SCRIPTS_DIR}/gen-resources.py + COMMAND ${PYTHON_EXEC} ${SCRIPTS_DIR}/gen_resources_qrc.py WORKING_DIRECTORY ${APP_SRC_DIR}) # library compatibility (boost, libnotify, etc.) diff --git a/INSTALL.md b/INSTALL.md index b58fdcff0..1ea9a4712 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -59,7 +59,7 @@ Then, you can build the 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 cd jami-project/ @@ -157,13 +157,13 @@ Only 64-bit MSVC build can be compiled. - Qt WebSockets - 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 | -- 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 | | -------------------- | ---------- | @@ -197,14 +197,14 @@ Only 64-bit MSVC build can be compiled. ``` > **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 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. -When that happens you need to compile the client separately: +> When that happens you need to compile the client separately: ```bash python build.py --install diff --git a/extras/scripts/gen-resources.py b/extras/scripts/gen_resources_qrc.py similarity index 50% rename from extras/scripts/gen-resources.py rename to extras/scripts/gen_resources_qrc.py index c5b73361f..58b1f242f 100644 --- a/extras/scripts/gen-resources.py +++ b/extras/scripts/gen_resources_qrc.py @@ -1,8 +1,8 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + # 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 # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or @@ -15,10 +15,17 @@ # # You should have received a copy of the GNU General Public License # 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 sys import re # These paths should be relative to the working directory of the @@ -27,32 +34,44 @@ import re resdir = os.path.join('..', '..', 'resources') qmlfile = os.path.join('constant', 'JamiResources.qml') 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') - 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): if len(files): 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: # 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)) + qrc.write(f'\t\t<file alias="{filename}">{filepath}</file>\n') # 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('/', 3)[-1])) + if re.match("icons|images", prefix): + resource = f'qrc:/{prefix}/{filename}' + qml.write( + " readonly property string" + f' {format_qml_prop(filename)}:' + f' "{resource}"\n' + ) qrc.write('\t</qresource>\n') qml.write('}') qrc.write('</RCC>') -- GitLab