diff --git a/metadata.txt b/metadata.txt index 6b8f37bc..074cbf2f 100644 --- a/metadata.txt +++ b/metadata.txt @@ -11,15 +11,16 @@ tracker=https://github.com/QGIS-Contribution/QGIS-ResourceSharing/issues repository=https://github.com/QGIS-Contribution/QGIS-ResourceSharing.git qgisMaximumVersion=3.98 -tags=collections,sharing,processing,algorithms,Python,R,model,script,style,svg,symbol,repository,design,maps,checklist +tags=collections,sharing,processing,algorithms,Python,R,model,script,style,svg,symbol,checklist,repository,design,maps homepage=http://qgis-contribution.github.io/QGIS-ResourceSharing/ experimental=False deprecated=False icon=resources/icon.png changelog= - 0.15.2 - GUI improvements (#138, #139, #140, #141) + 0.16.0 - GUI improvements (#138, #139, #140, #141) - Add button for reloading the QGIS directory of approved resources (#145) - Fix bug in the handling of QGIS directory updates (#146) + - Add support for checklists (#151) - @ricardogsilva 0.15.1 - Fix incorrect handling of searchPathsForSVG setting (#135) - Handle XML parsing exceptions for QML files 0.15.0 - Support expressions (#130). Switch to Python pathlib. diff --git a/resource_sharing/collection_manager.py b/resource_sharing/collection_manager.py index 8a9f7144..42c780e3 100644 --- a/resource_sharing/collection_manager.py +++ b/resource_sharing/collection_manager.py @@ -10,9 +10,10 @@ from resource_sharing import config from resource_sharing.config import ( - COLLECTION_INSTALLED_STATUS, COLLECTION_NOT_INSTALLED_STATUS) + COLLECTION_INSTALLED_STATUS, + COLLECTION_NOT_INSTALLED_STATUS) from resource_sharing.utilities import ( - RESOURCE_MAP, + SUPPORTED_RESOURCES_MAP, local_collection_path, render_template, resources_path) @@ -94,18 +95,19 @@ def get_html(self, collection_id): """ html = '' resource_types = 0 - for type_, description in RESOURCE_MAP.items(): + for type_, desc in SUPPORTED_RESOURCES_MAP.items(): if type_ in config.COLLECTIONS[collection_id].keys(): if resource_types > 0: html += ', ' - html += f'{config.COLLECTIONS[collection_id][type_]} {description}' + html += f'{config.COLLECTIONS[collection_id][type_]} {desc}' if config.COLLECTIONS[collection_id][type_] > 1: html += 's' resource_types += 1 html = html + '.
Reinstall to update' if resource_types == 0: html = 'No standard resources found.' - if config.COLLECTIONS[collection_id]['status'] != COLLECTION_INSTALLED_STATUS: + if (config.COLLECTIONS[collection_id]['status'] != + COLLECTION_INSTALLED_STATUS): html = 'Unknown before installation' config.COLLECTIONS[collection_id]['resources_html'] = html diff --git a/resource_sharing/gui/resource_sharing_dialog.py b/resource_sharing/gui/resource_sharing_dialog.py index 9f121b45..ecfe37bf 100644 --- a/resource_sharing/gui/resource_sharing_dialog.py +++ b/resource_sharing/gui/resource_sharing_dialog.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ /*************************************************************************** - A QGIS plugin + QGIS Resource Sharing - a QGIS plugin Download collections shared by other users ------------------- begin : 2016-05-29 @@ -60,7 +60,7 @@ CollectionManager, CollectionInstaller) from resource_sharing.utilities import ( - RESOURCE_MAP, + SUPPORTED_RESOURCES_MAP, resources_path, ui_path, repo_settings_group, @@ -473,15 +473,17 @@ def install_finished(self): message = ('%s was successfully installed, ' 'containing:\n' - QMessageBox.information(self, 'Resource Sharing', message) + QMessageBox.information(self, 'Resource Sharing', message) self.populate_repositories_widget() # Set the selection oldRow = self.current_index.row() diff --git a/resource_sharing/resource_handler/checklist_handler.py b/resource_sharing/resource_handler/checklist_handler.py index e2660b4a..62c6120a 100644 --- a/resource_sharing/resource_handler/checklist_handler.py +++ b/resource_sharing/resource_handler/checklist_handler.py @@ -1,17 +1,12 @@ # coding=utf-8 -import logging from pathlib import Path import shutil -import typing +import logging -from qgis.core import ( - QgsApplication, - QgsMessageLog, -) +from qgis.core import QgsApplication +from qgis.PyQt.QtCore import QDir, QSettings from resource_sharing.resource_handler.base import BaseResourceHandler -from resource_sharing.utilities import get_profile_base_path - CHECKLISTS_FOLDER = 'checklists' CHECKLISTS = 'checklists' # Resource Sharing collection subdirectory name @@ -25,7 +20,8 @@ class ChecklistHandler(BaseResourceHandler): @property def checklists_directory(self) -> Path: - return get_profile_base_path() / 'checklists' + chkl_path = Path(QgsApplication.qgisSettingsDirPath()) / 'checklists/' + return Path(chkl_path) @classmethod def dir_name(cls): @@ -36,14 +32,13 @@ def install(self): Copy the checklists in the checklists directory of the Resource Sharing collection to the user's checklists directory. - """ valid = 0 + self.checklists_directory.mkdir(parents=False, exist_ok=True) for item in self.resource_dir.glob(self._GLOB_PATTERN): - QgsMessageLog.logMessage(f'Processing file {item!r}...') try: - shutil.copy(item, self.checklists_directory) + shutil.copy(item, self.checklists_directory / Path(item).name) valid += 1 except OSError as exc: LOGGER.error(f"Could not copy checklist {item!r}:\n{str(exc)}") @@ -52,7 +47,18 @@ def install(self): def uninstall(self): """Uninstall the collection's checklists.""" - for item in self.resource_dir.glob(self._GLOB_PATTERN): - checklist_path = Path(self.checklists_directory, item.name) - if checklist_path.exists(): - checklist_path.unlink() \ No newline at end of file + if self.checklists_directory.exists(): + for item in self.resource_dir.glob(self._GLOB_PATTERN): + chkl_file = Path(self.checklists_directory, item.name) + if chkl_file.exists(): + chkl_file.unlink() + else: + LOGGER.info('Item already removed: ' + str(chkl_file)) + # Remove the user's checklist directory, if empty + # (unlink will not remove a non-empty directory, but raises + # an exception) + if not any(self.checklists_directory.iterdir()): + self.checklists_directory.rmdir() + else: + LOGGER.info('No checklist directory') + diff --git a/resource_sharing/utilities.py b/resource_sharing/utilities.py index 310c798c..abb50645 100644 --- a/resource_sharing/utilities.py +++ b/resource_sharing/utilities.py @@ -14,18 +14,17 @@ LOGGER = logging.getLogger('QGIS Resource Sharing') -RESOURCE_MAP = { - 'svg': 'SVG file', +SUPPORTED_RESOURCES_MAP = { + 'svg': 'SVG', 'style': 'Layer style (QML) file', 'symbol': 'Symbol (XML) file', - 'models': 'Processing model', 'expressions': 'Expression (JSON) file', 'processing': 'Processing script', + 'models': 'Processing model', 'rscripts': 'R script', - 'checklists': 'Checklist', + 'checklists': 'QA Workbench checklist', } - def resources_path(*args): """Get the absolute path to resources in the resources dir. @@ -41,7 +40,6 @@ def resources_path(*args): path = (path / item) return path - def ui_path(*args): """Get the absolute path to the ui file from the UI dir. @@ -57,38 +55,31 @@ def ui_path(*args): path = (path / item) return path - def user_expressions_group(): """Get the user expressions group.""" return '/expressions/user' - def repo_settings_group(): """Get the settings group for Resource Sharing Dialog.""" return '/ResourceSharing/repository' - def resource_sharing_group(): """Get the settings group for the local collection directories.""" return '/ResourceSharing' - def repositories_cache_path(): """Get the path to the repositories cache.""" return Path(QgsApplication.qgisSettingsDirPath(), 'resource_sharing', 'repositories_cache') - def local_collection_root_dir_key(): """The QSettings key for the local collections root dir.""" return 'localCollectionDir' - def default_local_collection_root_dir(): return Path(QgsApplication.qgisSettingsDirPath(), 'resource_sharing', 'collections') - def local_collection_path(id=None): """Get the path to the local collection dir. @@ -137,7 +128,6 @@ def local_collection_path(id=None): pass return path - def old_local_collection_path(id=None): """Get the path to the old local collection dir. (in case we would like to help the users migrate) @@ -167,7 +157,6 @@ def qgis_version(): version = int(version) return version - def render_template(filename, context): """Render a template with the specified filename. :param filename: The filename (must be in the template directory) @@ -182,6 +171,3 @@ def render_template(filename, context): loader=jinja2.FileSystemLoader(str(path)) ).get_template(filename).render(context) - -def get_profile_base_path() -> Path: - return Path(QgsApplication.qgisSettingsDirPath()) \ No newline at end of file