Skip to content

Commit

Permalink
Update the files (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
havatv authored Aug 29, 2020
1 parent 9557920 commit cf88721
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 47 deletions.
5 changes: 3 additions & 2 deletions metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions resource_sharing/collection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 + '.<br><i>Reinstall</i> to update'
if resource_types == 0:
html = '<i>No standard resources found</i>.'
if config.COLLECTIONS[collection_id]['status'] != COLLECTION_INSTALLED_STATUS:
if (config.COLLECTIONS[collection_id]['status'] !=
COLLECTION_INSTALLED_STATUS):
html = '<i>Unknown before installation</i>'

config.COLLECTIONS[collection_id]['resources_html'] = html
Expand Down
14 changes: 8 additions & 6 deletions resource_sharing/gui/resource_sharing_dialog.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -60,7 +60,7 @@
CollectionManager,
CollectionInstaller)
from resource_sharing.utilities import (
RESOURCE_MAP,
SUPPORTED_RESOURCES_MAP,
resources_path,
ui_path,
repo_settings_group,
Expand Down Expand Up @@ -473,15 +473,17 @@ def install_finished(self):
message = ('<b>%s</b> was successfully installed, '
'containing:\n<ul>' %
(config.COLLECTIONS[self._sel_coll_id]['name']))
for type_, description in RESOURCE_MAP.items():
number = 0
for type_, description in SUPPORTED_RESOURCES_MAP.items():
if type_ in config.COLLECTIONS[self._sel_coll_id].keys():
num = config.COLLECTIONS[self._sel_coll_id][type_]
number = config.COLLECTIONS[self._sel_coll_id][type_]
message += (
f'\n<li>{num} {description}{"s" if num > 1 else ""}'
f'\n<li>{number} {description}'
f'{"s" if number > 1 else ""}'
f'</li>'
)
message += '\n</ul>'
QMessageBox.information(self, 'Resource Sharing', message)
QMessageBox.information(self, 'Resource Sharing', message)
self.populate_repositories_widget()
# Set the selection
oldRow = self.current_index.row()
Expand Down
38 changes: 22 additions & 16 deletions resource_sharing/resource_handler/checklist_handler.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand All @@ -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)}")
Expand All @@ -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()
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')

22 changes: 4 additions & 18 deletions resource_sharing/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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())

0 comments on commit cf88721

Please sign in to comment.