Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide installation summary after collection installation #102

Merged
merged 24 commits into from
Mar 30, 2020
35 changes: 34 additions & 1 deletion resource_sharing/gui/resource_sharing_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,41 @@ def install_finished(self):
self.progress_dialog.hide()
if self.installer_worker.install_status:
self.reload_collections_model()
message = '%s is installed successfully' % (
# Report what has been installed
message = '<b>%s</b> was successfully installed, containing:\n<ul>' % (
config.COLLECTIONS[self._selected_collection_id]['name'])
number = 0
if 'style' in config.COLLECTIONS[self._selected_collection_id].keys():
number = config.COLLECTIONS[self._selected_collection_id]['style']
message = message + '\n<li> ' + str(config.COLLECTIONS[self._selected_collection_id]['style']) + ' Layer style (QML) file'
if number > 1:
message = message + 's'
if 'symbol' in config.COLLECTIONS[self._selected_collection_id].keys():
number = config.COLLECTIONS[self._selected_collection_id]['symbol']
message = message + '\n<li> ' + str(config.COLLECTIONS[self._selected_collection_id]['symbol']) + ' XML symbol file'
if number > 1:
message = message + 's'
if 'svg' in config.COLLECTIONS[self._selected_collection_id].keys():
number = config.COLLECTIONS[self._selected_collection_id]['svg']
message = message + '\n<li> ' + str(config.COLLECTIONS[self._selected_collection_id]['svg']) + ' SVG file'
if number > 1:
message = message + 's'
if 'models' in config.COLLECTIONS[self._selected_collection_id].keys():
number = config.COLLECTIONS[self._selected_collection_id]['models']
message = message + '\n<li> ' + str(config.COLLECTIONS[self._selected_collection_id]['models']) + ' model'
if number > 1:
message = message + 's'
if 'processing' in config.COLLECTIONS[self._selected_collection_id].keys():
number = config.COLLECTIONS[self._selected_collection_id]['processing']
message = message + '\n<li> ' + str(config.COLLECTIONS[self._selected_collection_id]['processing']) + ' processing script'
if number > 1:
message = message + 's'
if 'rscripts' in config.COLLECTIONS[self._selected_collection_id].keys():
number = config.COLLECTIONS[self._selected_collection_id]['rscripts']
message = message + '\n<li> ' + str(number) + ' R script'
if number > 1:
message = message + 's'
message = message + '\n</ul>'
else:
message = self.installer_worker.error_message
QMessageBox.information(self, 'Resource Sharing', message)
Expand Down
3 changes: 2 additions & 1 deletion resource_sharing/resource_handler/model_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def install(self):
Resource Sharing collection to the user's processing
model directory and refresh the provider.
"""
# Check if the dir exists, return silently if it doesn't
# Return silently if the directory does not exist
# if Path(self.resource_dir).exists():
if not os.path.exists(self.resource_dir):
return
Expand All @@ -58,6 +58,7 @@ def install(self):
str(model_file) + "':\n" + str(e))
if valid > 0:
self.refresh_Model_provider()
self.collection[MODELS] = valid

def uninstall(self):
"""Uninstall the models from processing toolbox."""
Expand Down
42 changes: 28 additions & 14 deletions resource_sharing/resource_handler/processing_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from qgis.core import QgsApplication
LOGGER = logging.getLogger('QGIS Resource Sharing')
PROCESSING = 'processing'


class ProcessingScriptHandler(BaseResourceHandler):
Expand All @@ -21,15 +22,15 @@ def __init__(self, collection_id):

@classmethod
def dir_name(cls):
return 'processing'
return PROCESSING

def install(self):
"""Install the processing scripts in the collection.
"""Install the processing scripts of the collection.

We copy the processing scripts exist in the processing dir to the
user's processing scripts directory and refresh the provider.
We copy the processing scripts to the user's processing
scripts directory, and refresh the provider.
"""
# Check if the dir exists, pass installing silently if it doesn't exist
# Pass silently if the directory does not exist
if not os.path.exists(self.resource_dir):
return

Expand All @@ -42,25 +43,38 @@ def install(self):

valid = 0
for processing_file in processing_files:
# Install silently the processing file
try:
shutil.copy(processing_file, self.scripts_folder())
valid += 1
except OSError as e:
LOGGER.error("Could not copy script '" +
# Install the processing file silently
try:
shutil.copy(processing_file, self.scripts_folder())
valid += 1
except OSError as e:
LOGGER.error("Could not copy script '" +
str(processing_file) + "'\n" + str(e))
if valid > 0:
self.refresh_script_provider()
self.collection[PROCESSING] = valid

def uninstall(self):
"""Uninstall the processing scripts from processing toolbox."""
# Remove the script files containing substring collection_id
for item in os.listdir(self.scripts_folder()):
if fnmatch.fnmatch(item, '*%s*' % self.collection_id):
# if not Path(self.resource_dir).exists():
if not os.path.exists(self.resource_dir):
return
# Remove the processing script files that are present in this
# collection
for item in os.listdir(self.resource_dir):
# file_path = self.resource_dir / item)
file_path = os.path.join(self.resource_dir, item)
if fnmatch.fnmatch(file_path, '*%s*' % self.collection_id):
script_path = os.path.join(self.scripts_folder(), item)
if os.path.exists(script_path):
os.remove(script_path)

#for item in os.listdir(self.scripts_folder()):
# if fnmatch.fnmatch(item, '*%s*' % self.collection_id):
# script_path = os.path.join(self.scripts_folder(), item)
# if os.path.exists(script_path):
# os.remove(script_path)

self.refresh_script_provider()

def refresh_script_provider(self):
Expand Down
4 changes: 2 additions & 2 deletions resource_sharing/resource_handler/r_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ def install(self):
"'\n" + str(e))
if valid > 0:
self.refresh_Rscript_provider()
self.collection[RSCRIPTS_FOLDER] = valid

def uninstall(self):
"""Uninstall the r scripts from processing toolbox."""
"""Uninstall the R scripts from processing toolbox."""
# if not Path(self.resource_dir).exists():
if not os.path.exists(self.resource_dir):
return
Expand All @@ -77,7 +78,6 @@ def uninstall(self):
script_path = os.path.join(self.RScripts_folder(), item)
if os.path.exists(script_path):
os.remove(script_path)

self.refresh_Rscript_provider()

def refresh_Rscript_provider(self):
Expand Down
20 changes: 14 additions & 6 deletions resource_sharing/resource_handler/style_handler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# coding=utf-8
import os
import fnmatch
import logging

from resource_sharing.resource_handler.base import BaseResourceHandler
from resource_sharing.resource_handler.symbol_resolver_mixin import \
SymbolResolverMixin

LOGGER = logging.getLogger('QGIS Resource Sharing')
STYLE = 'style'

class StyleResourceHandler(BaseResourceHandler, SymbolResolverMixin):
"""Concrete class of the style handler."""
"""Style handler class."""
IS_DISABLED = False

def __init__(self, collection_id):
Expand All @@ -17,12 +20,12 @@ def __init__(self, collection_id):

@classmethod
def dir_name(cls):
return 'style'
return STYLE

def install(self):
"""Install the style.

We just resolve the symbol svg/image path in the qml file
We just resolve the symbol SVG/image path in the QML file
"""
# Check if the dir exists, pass installing silently if it doesn't exist
if not os.path.exists(self.resource_dir):
Expand All @@ -35,14 +38,19 @@ def install(self):
if fnmatch.fnmatch(file_path, '*.qml'):
style_files.append(file_path)

# If there's no symbol files don't do anything
# Nothing to do if there are no symbol files
if len(style_files) == 0:
return

valid = 0
for style_file in style_files:
# Modify the style
# Try to fix image and PNG paths in the QML file
self.resolve_dependency(style_file)
valid += 1
if valid >= 0:
self.collection[STYLE] = valid

def uninstall(self):
"""Uninstall the style from QGIS."""
"""Uninstall the style."""
# The style is not installed, so do nothing.
pass
33 changes: 23 additions & 10 deletions resource_sharing/resource_handler/svg_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# coding=utf-8
import os
import fnmatch
import logging

from qgis.PyQt.QtCore import QSettings
from qgis.core import QgsSettings
Expand All @@ -11,18 +13,20 @@
from resource_sharing.resource_handler.base import BaseResourceHandler
from resource_sharing.utilities import local_collection_path

SVG = 'svg'
LOGGER = logging.getLogger('QGIS Resource Sharing')

class SVGResourceHandler(BaseResourceHandler):
"""Concrete class of the SVG resource handler."""
"""The SVG resource handler class."""
IS_DISABLED = False

def __init__(self, collection_id):
"""Constructor of the base class."""
"""Base class constructor."""
BaseResourceHandler.__init__(self, collection_id)

@classmethod
def svg_search_paths(cls):
"""Return a list of SVG paths read from settings"""
"""Read the SVG paths from settings"""
# settings = QSettings()
settings = QgsSettings()
search_paths_str = settings.value('svg/searchPathsForSVG')
Expand All @@ -39,7 +43,7 @@ def svg_search_paths(cls):

@classmethod
def set_svg_search_paths(cls, paths):
"""Set a list of SVG paths read from settings"""
"""Write the list of SVG paths to settings"""
# settings = QSettings()
settings = QgsSettings()
if Qgis.QGIS_VERSION_INT < 29900:
Expand All @@ -49,18 +53,17 @@ def set_svg_search_paths(cls, paths):

@classmethod
def dir_name(cls):
return 'svg'
return SVG

def install(self):
"""Install the SVGs from this collection in to QGIS.
"""Install the SVGs from this collection.

We simply just add the path to the collection root directory to search
path in QGIS.
We just add the collection root directory path to the
SVG search path.
"""
# Check if the dir exists, pass installing silently if it doesn't exist
if not os.path.exists(self.resource_dir):
return

# Add to the search paths for SVG
search_paths = self.svg_search_paths()

Expand All @@ -69,9 +72,19 @@ def install(self):

self.set_svg_search_paths(search_paths)

# Count the SVGs
valid = 0
for item in os.listdir(self.resource_dir):
# file_path = self.resource_dir / item)
file_path = os.path.join(self.resource_dir, item)
if fnmatch.fnmatch(file_path, '*.svg'):
valid += 1
if valid >= 0:
self.collection[SVG] = valid

def uninstall(self):
"""Uninstall the SVGs from QGIS."""
# Remove from the searchPaths if the dir empty of collection
# Remove from the SVG search paths if the directory is empty
search_paths = self.svg_search_paths()
collection_directories = os.listdir(local_collection_path())

Expand Down
Loading