From b2cb5c650b1cc88ec79efd492d25896357d68f73 Mon Sep 17 00:00:00 2001 From: Jean Felder Date: Wed, 6 Mar 2024 12:54:18 +0100 Subject: [PATCH 1/2] repository_handler: Do not use reserved keyword id This shadows the builtin keyword id. --- qgis_resource_sharing/repository_handler/base.py | 6 +++--- .../repository_handler/filesystem_handler.py | 8 ++++---- .../repository_handler/remote_git_handler.py | 8 ++++---- .../repository_handler/remote_zip_handler.py | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/qgis_resource_sharing/repository_handler/base.py b/qgis_resource_sharing/repository_handler/base.py index e07c43c2..d139df02 100644 --- a/qgis_resource_sharing/repository_handler/base.py +++ b/qgis_resource_sharing/repository_handler/base.py @@ -247,11 +247,11 @@ def parse_metadata(self) -> List[Dict]: return collections - def download_collection(self, id, register_name): + def download_collection(self, collection_id, register_name): """Download a collection given its ID. - :param id: The ID of the collection. - :type id: str + :param collection_id: The ID of the collection. + :type collection_id: str :param register_name: The register name of the collection (the section name of the collection) diff --git a/qgis_resource_sharing/repository_handler/filesystem_handler.py b/qgis_resource_sharing/repository_handler/filesystem_handler.py index 17e46686..a3a83022 100644 --- a/qgis_resource_sharing/repository_handler/filesystem_handler.py +++ b/qgis_resource_sharing/repository_handler/filesystem_handler.py @@ -42,11 +42,11 @@ def fetch_metadata(self): return True, message - def download_collection(self, id, register_name): + def download_collection(self, collection_id, register_name): """Download a collection given its ID. - :param id: The ID of the collection. - :type id: str + :param collection_id: The ID of the collection. + :type collection_id: str :param register_name: The register name of the collection (the section name of the collection) @@ -58,7 +58,7 @@ def download_collection(self, id, register_name): error_message = "Error: The collection does not exist in the " "repository." return False, error_message - dest_dir = local_collection_path(id) + dest_dir = local_collection_path(collection_id) if dest_dir.exists(): shutil.rmtree(str(dest_dir)) shutil.copytree(str(src_dir), str(dest_dir)) diff --git a/qgis_resource_sharing/repository_handler/remote_git_handler.py b/qgis_resource_sharing/repository_handler/remote_git_handler.py index 45154f3c..0a6a17f1 100644 --- a/qgis_resource_sharing/repository_handler/remote_git_handler.py +++ b/qgis_resource_sharing/repository_handler/remote_git_handler.py @@ -81,15 +81,15 @@ def git_owner(self): def git_repository(self): return self._git_repository - def download_collection(self, id: str, register_name: str) -> tuple: + def download_collection(self, collection_id: str, register_name: str) -> tuple: """Download a collection given its ID. For remote git repositories, we will clone the repository (or pull if the repo is already cloned), and copy the collection to the collections directory. - :param id: The ID of the collection. - :type id: str + :param collection_id: The ID of the collection. + :type collection_id: str :param register_name: The register name of the collection (the section name of the collection) :type register_name: unicode @@ -186,7 +186,7 @@ def download_collection(self, id: str, register_name: str) -> tuple: error_message = "Error: The collection does not exist in the repository." return False, error_message - dest_dir = local_collection_path(id) + dest_dir = local_collection_path(collection_id) if dest_dir.exists(): # Remove the existing collection directory shutil.rmtree(str(dest_dir)) diff --git a/qgis_resource_sharing/repository_handler/remote_zip_handler.py b/qgis_resource_sharing/repository_handler/remote_zip_handler.py index e1c8c248..b2fc7e52 100644 --- a/qgis_resource_sharing/repository_handler/remote_zip_handler.py +++ b/qgis_resource_sharing/repository_handler/remote_zip_handler.py @@ -26,14 +26,14 @@ def can_handle(self): return True return False - def download_collection(self, id, register_name): + def download_collection(self, collection_id, register_name): """Download a collection given its ID. For zip collection, we will download the zip, and extract the collection to collections dir. - :param id: The ID of the collection. - :type id: str + :param collection_id: The ID of the collection. + :type collection_id: str :param register_name: The register name of the collection (the section name of the collection) @@ -54,7 +54,7 @@ def download_collection(self, id, register_name): zip_file.close() zf = ZipFile(zip_file.fileName()) - zf.extractall(path=local_collection_path(id)) + zf.extractall(path=local_collection_path(collection_id)) return True, None def file_url(self, relative_path): From cf20f19ca9a0a9352cd2515e6a8982c2a5754ddc Mon Sep 17 00:00:00 2001 From: Jean Felder Date: Wed, 6 Mar 2024 12:56:51 +0100 Subject: [PATCH 2/2] resource_sharing_dialog: Do not use reserved keyword id This shadows the builtin keyword id. --- .../gui/resource_sharing_dialog.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/qgis_resource_sharing/gui/resource_sharing_dialog.py b/qgis_resource_sharing/gui/resource_sharing_dialog.py index 83972356..cd52c710 100644 --- a/qgis_resource_sharing/gui/resource_sharing_dialog.py +++ b/qgis_resource_sharing/gui/resource_sharing_dialog.py @@ -642,25 +642,25 @@ def reload_collections_model(self): """Reload the collections model with the current collections.""" self.collections_model.clear() installed_collections = self.collection_manager.get_installed_collections() - for id in config.COLLECTIONS: - collection_name = config.COLLECTIONS[id]["name"] - collection_author = config.COLLECTIONS[id]["author"] - collection_tags = config.COLLECTIONS[id]["tags"] - collection_description = config.COLLECTIONS[id]["description"] - collection_status = config.COLLECTIONS[id]["status"] + for collection_id in config.COLLECTIONS: + collection_name = config.COLLECTIONS[collection_id]["name"] + collection_author = config.COLLECTIONS[collection_id]["author"] + collection_tags = config.COLLECTIONS[collection_id]["tags"] + collection_description = config.COLLECTIONS[collection_id]["description"] + collection_status = config.COLLECTIONS[collection_id]["status"] repository_name = "" - if "repository_name" in config.COLLECTIONS[id].keys(): - repository_name = config.COLLECTIONS[id]["repository_name"] + if "repository_name" in config.COLLECTIONS[collection_id].keys(): + repository_name = config.COLLECTIONS[collection_id]["repository_name"] item = QStandardItem(collection_name + " (" + repository_name + ")") item.setEditable(False) - item.setData(id, COLLECTION_ID_ROLE) + item.setData(collection_id, COLLECTION_ID_ROLE) item.setData(collection_name, COLLECTION_NAME_ROLE) item.setData(collection_description, COLLECTION_DESCRIPTION_ROLE) item.setData(collection_author, COLLECTION_AUTHOR_ROLE) item.setData(collection_tags, COLLECTION_TAGS_ROLE) item.setData(collection_status, COLLECTION_STATUS_ROLE) # Make installed collections stand out - if installed_collections and id in installed_collections.keys(): + if installed_collections and collection_id in installed_collections.keys(): collectionFont = QFont() collectionFont.setWeight(60) item.setFont(collectionFont) @@ -722,9 +722,9 @@ def filter_collections(self, text): search = QRegExp(text, Qt.CaseInsensitive, QRegExp.RegExp) self.collection_proxy.setFilterRegExp(search) - def show_collection_metadata(self, id): + def show_collection_metadata(self, collection_id): """Show the collection metadata given the ID.""" - html = self.collection_manager.get_html(id) + html = self.collection_manager.get_html(collection_id) self.web_view_details.setHtml(html) def reject(self):