From ca93b54451048b943f6e9be481a945ce142c7dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Tveite?= Date: Sat, 25 Apr 2020 16:19:26 +0200 Subject: [PATCH] Symbolxml 3.4 (#128) * QGIS 3.4 does not support labelsettings and textformats in styles * check if directory exists before removing * move thread cleanup forward * remove repo * Testing * fix * Update metadata.txt - prepare for release --- metadata.txt | 6 ++++-- .../gui/resource_sharing_dialog.py | 18 ++++++++++-------- .../repository_handler/remote_git_handler.py | 16 +++++++++++++--- .../resource_handler/symbol_handler.py | 10 ++++++++++ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/metadata.txt b/metadata.txt index 19115475..f6675b11 100644 --- a/metadata.txt +++ b/metadata.txt @@ -6,7 +6,7 @@ author=Akbar Gumbira, HÃ¥vard Tveite qgisMinimumVersion=3.0 description=Download shared collections about=Search for published collections and install them for use with QGIS. Symbology (SVG, images, styles), Processing scripts, Processing models and R scripts are supported. There are several options for repositories: Github, Bitbucket, local file system and HTTP(S). -version=0.14.0 +version=0.14.1 tracker=https://github.com/QGIS-Contribution/QGIS-ResourceSharing/issues repository=https://github.com/QGIS-Contribution/QGIS-ResourceSharing.git @@ -17,8 +17,10 @@ experimental=False deprecated=False icon=resources/icon.png changelog= + 0.14.1 - Also support QGIS 3.4 (avoid install of style labelsettings and textformatting for v. < 3.10 - #127) + - Try another way to avoid [WinError 5] on Microsoft Windows (#103) 0.14.0 - Style import improvements (fix colorramp support, add support for label settings and text formats, clean up Style Manager tags) (#113, #114, #116, #118) - - Change collection directory names from a hash to more user friendly name (composition of the name of the collection and its repository) (#110) + - Change collection directory names from a hash to a more user friendly name (composition of the name of the collection and its repository) (#110) - Preserve the installed collections when renaming a repository (#121) - Documentation updates (#105, #109, #113) 0.13.1 - Fix #44 (files removed from repository are still being installed from cache) diff --git a/resource_sharing/gui/resource_sharing_dialog.py b/resource_sharing/gui/resource_sharing_dialog.py index 34b714da..7dc56db0 100644 --- a/resource_sharing/gui/resource_sharing_dialog.py +++ b/resource_sharing/gui/resource_sharing_dialog.py @@ -470,7 +470,16 @@ def install_collection(self): def install_finished(self): # Process the result self.progress_dialog.hide() - if self.installer_worker.install_status: + installStatus = self.installer_worker.install_status + if not installStatus: + message = self.installer_worker.error_message + # Clean up the worker and thread + self.installer_worker.deleteLater() + self.installer_thread.quit() + self.installer_thread.wait() + self.installer_thread.deleteLater() + + if installStatus: self.reload_collections_model() # Report what has been installed message = '%s was successfully installed, containing:\n' - else: - message = self.installer_worker.error_message QMessageBox.information(self, 'Resource Sharing', message) - # Clean up the worker and thread - self.installer_worker.deleteLater() - self.installer_thread.quit() - self.installer_thread.wait() - self.installer_thread.deleteLater() self.populate_repositories_widget() # Set the selection oldRow = self.current_index.row() diff --git a/resource_sharing/repository_handler/remote_git_handler.py b/resource_sharing/repository_handler/remote_git_handler.py index 85d63de6..252930b2 100644 --- a/resource_sharing/repository_handler/remote_git_handler.py +++ b/resource_sharing/repository_handler/remote_git_handler.py @@ -98,13 +98,19 @@ def download_collection(self, id, register_name): """ # Hack to avoid irritating Dulwich / Porcelain ResourceWarning warnings.filterwarnings("ignore", category=ResourceWarning) - # Clone or pull the repositories first + # Clone or pull the repositories first local_repo_dir = os.path.join( QgsApplication.qgisSettingsDirPath(), 'resource_sharing', 'repositories', self.git_host, self.git_owner, self.git_repository ) + # Hack to try to avoid sharing errors + if os.path.exists(local_repo_dir): + try: + shutil.rmtree(local_repo_dir) + except: + pass if not os.path.exists(os.path.join(local_repo_dir, '.git')): os.makedirs(local_repo_dir) try: @@ -137,8 +143,12 @@ def download_collection(self, id, register_name): return False, error_message else: # Hack until dulwich/porcelain handles file removal - collDir = os.path.join(local_repo_dir, 'collections') - shutil.rmtree(collDir) + #collDir = os.path.join(local_repo_dir, 'collections') + # ????!!!! + #if os.path.exists(collDir): + # shutil.rmtree(collDir) + if os.path.exists(local_repo_dir): + shutil.rmtree(local_repo_dir) try: porcelain.pull( local_repo_dir, diff --git a/resource_sharing/resource_handler/symbol_handler.py b/resource_sharing/resource_handler/symbol_handler.py index db85534f..7bcd7ca1 100644 --- a/resource_sharing/resource_handler/symbol_handler.py +++ b/resource_sharing/resource_handler/symbol_handler.py @@ -12,6 +12,7 @@ from resource_sharing.symbol_xml_extractor import SymbolXMLExtractor from resource_sharing.resource_handler.symbol_resolver_mixin import \ SymbolResolverMixin +from resource_sharing.utilities import qgis_version LOGGER = logging.getLogger('QGIS Resource Sharing') SYMBOL = 'symbol' @@ -174,6 +175,9 @@ def install(self): colorramp_name, colorramp['colorramp'], True): self._group_or_tag(QgsStyle.ColorrampEntity, colorramp_name, groupOrTag_id) + # textformat and labelsettings were introduced in QGIS 3.10 + if qgis_version() < 31000: + continue for textformat in symbol_xml_extractor.textformats: textformat_name = '%s (%s)' % ( textformat['name'], self.collection['repository_name']) @@ -208,6 +212,12 @@ def uninstall(self): QgsStyle.ColorrampEntity, child_group_id) for colorramp in colorramps: self.style.removeColorRamp(colorramp) + + # textformat and labelsettings were introduced in QGIS 3.10 + if qgis_version() < 31000: + # Remove this tag / child group + self._group_or_tag_remove(child_group_id) + continue # Get all the textformats for this tag / child group and remove them textformats = self._get_symbols_for_group_or_tag( QgsStyle.TextFormatEntity, child_group_id)