Skip to content

Commit

Permalink
Remove svg uninstall (#107)
Browse files Browse the repository at this point in the history
* Remove SVGs on uninstall

* unset selected on uninstall

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* Remove SVGs on uninstall

* unset selected on uninstall

* testing

* rebase fix

* testing

* rebase fix

* rebase fix

* rebase fix

* testing

* Some more updates

* Cleaning

* testing

* testing

* Fix svg counting, add installation summary to collection details

* Enable SVG path update on removal of the last SVG file

* Fix line continuation

* fix

* fix

* fix

* fix

* fix

* fix

* increase GUI consistency after install / uninstall

* testing

* update web_view_details on uninstall

* fix svg remove error

* remove blank line

* set svg search_paths

* handle removal of the last installed collection

* use correct collection ID

* testing

* update _selected_collection_id

* include collection statistics docs

* removings some comments

* some adjustments

* update metadata.txt

* update comments

* show_collection_metadata after collection install

* Keep resource statistics whe reloading repositories
  • Loading branch information
havatv authored Apr 10, 2020
1 parent f9ff108 commit 2b3d3ac
Show file tree
Hide file tree
Showing 23 changed files with 318 additions and 206 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
QGIS Resource Sharing Plugin
============================
QGIS Resource Sharing allows sharing of resources (currently SVGs, symbols,
styles, color ramps, processing scripts and R scripts), and this plugin
gives you access to shared collections.
styles, color ramps, processing scripts, processing models and R scripts),
and this plugin gives you access to shared collections.

The [documentation](http://qgis-contribution.github.io/QGIS-ResourceSharing/)
explains how to use the plugin and how to share resources.
Expand All @@ -18,6 +18,6 @@ We have some branches that we use for our workflow:

* **master**: The latest stable version.

* **gh-pages**: This is the branch for the documentation hosted in github
pages (http://qgis-contribution.github.io/QGIS-ResourceSharing/). It's in markdown.
Make a PR to this branch if you want to change or add something to the documentation.
* **gh-pages**: This is the branch for the documentation (github pages -
http://qgis-contribution.github.io/QGIS-ResourceSharing/). It is in markdown.
Make a PR to this branch if you want to update the documentation.
6 changes: 4 additions & 2 deletions metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ experimental=False
deprecated=False
icon=resources/icon.png
changelog=
0.13.0 - Provide installation summary (#6)
0.13.0 - GUI updates (#100)
- Provide installation summary (#6)
- Avoid (parent) tag with no members in QGIS 3 style documents (#101)
- Fix some minor issues (#104, )
- Fix reloading problems ([WinError 5]) with Microsoft Windows (#103)
- Other minor issues (#104)
0.12.0 - Make font sizes OK on HiDPI systems (#3)
- Disable editing and removal of "official" repositories in Settings (#93)
- Avoid ResourceWarning when installing a collection (#95)
Expand Down
79 changes: 64 additions & 15 deletions resource_sharing/collection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def __init__(self, collection_manager, collection_id):
def run(self):
self.progress.emit('Downloading the collection...')

# We can't really kill the process here, so let's finish it even when
# user cancels the download process
# We can't kill the process here, so let us finish it even if
# the user cancels the download process
download_status, error_message = self._collection_manager.download(
self._collection_id)

# If at this point it's killed, let's abort and tell the main thread
# If at this point it is killed, so abort and tell the main thread
if self.killed:
self.aborted.emit()
return
Expand All @@ -56,7 +56,7 @@ def run(self):
self.finished.emit()
return

# Downloading is fine, It's not killed, let's install it
# Downloading is fine, It is not killed, let us install it
if not self.killed:
self.progress.emit('Installing the collection...')
try:
Expand All @@ -82,30 +82,79 @@ def __init__(self):
""""Utilities class related to collection."""

def get_collection_id(self, register_name, repo_url):
"""Generate id of a collection."""
"""Generate the collection ID."""
hash_object = hashlib.sha1((register_name + repo_url).encode('utf-8'))
hex_dig = hash_object.hexdigest()
return hex_dig

def get_html(self, collection_id):
"""Return the detail of a collection in HTML form given the id.
"""Return the details of a collection as HTML, given its id.
:param collection_id: The id of the collection
:type collection_id: str
"""
html = ''
resource_types = 0
if 'svg' in config.COLLECTIONS[collection_id].keys():
html = html + str(config.COLLECTIONS[collection_id]['svg']) + ' SVG'
if config.COLLECTIONS[collection_id]['svg'] > 1:
html = html + 's'
resource_types = resource_types + 1
if 'style' in config.COLLECTIONS[collection_id].keys():
if resource_types > 0:
html = html + ', '
html = html + str(config.COLLECTIONS[collection_id]['style']) + ' Layer style'
if config.COLLECTIONS[collection_id]['style'] > 1:
html = html + 's'
resource_types = resource_types + 1
if 'symbol' in config.COLLECTIONS[collection_id].keys():
if resource_types > 0:
html = html + ', '
html = html + str(config.COLLECTIONS[collection_id]['symbol']) + ' Symbol file'
if config.COLLECTIONS[collection_id]['symbol'] > 1:
html = html + 's'
resource_types = resource_types + 1
if 'models' in config.COLLECTIONS[collection_id].keys():
if resource_types > 0:
html = html + ', '
html = html + str(config.COLLECTIONS[collection_id]['models']) + ' Processing model'
if config.COLLECTIONS[collection_id]['models'] > 1:
html = html + 's'
resource_types = resource_types + 1
if 'processing' in config.COLLECTIONS[collection_id].keys():
if resource_types > 0:
html = html + ', '
html = html + str(config.COLLECTIONS[collection_id]['processing']) + ' Processing script'
if config.COLLECTIONS[collection_id]['processing'] > 1:
html = html + 's'
resource_types = resource_types + 1
if 'rscripts' in config.COLLECTIONS[collection_id].keys():
if resource_types > 0:
html = html + ', '
html = html + str(config.COLLECTIONS[collection_id]['rscripts']) + ' R script'
if config.COLLECTIONS[collection_id]['rscripts'] > 1:
html = html + 's'
resource_types = resource_types + 1
html = html + ' (<i>Reinstall</i> to update)'
if resource_types == 0:
html = 'Reinstall the collection to get statistics'
if config.COLLECTIONS[collection_id]['status'] != COLLECTION_INSTALLED_STATUS:
html = 'Unknown before installation'

config.COLLECTIONS[collection_id]['resources_html'] = html
context = {
'resources_path': resources_path(),
'collection': config.COLLECTIONS[collection_id]
}
return render_template('collection_details.html', context)

def get_installed_collections(self, repo_url=None):
"""Get all installed collections of a given repository url.
"""Get all installed collections for a given repository URL.
If repository url is not specified, it will return all the installed
collections.
If a URL is not specified, all the installed collections
will be returned.
:param repo_url: The repository url.
:param repo_url: The repository URL.
:type repo_url: str
:return: Subset of config.COLLECTIONS that meet the requirement
Expand All @@ -125,9 +174,9 @@ def get_installed_collections(self, repo_url=None):
return installed_collections

def download(self, collection_id):
"""Download a collection given the id.
"""Download a collection given its ID.
:param collection_id: The id of the collection about to be downloaded.
:param collection_id: The ID of the collection to be downloaded.
:type collection_id: str
:return: status (True or False), information from the repo handler
:rtype: (boolean, string)
Expand All @@ -144,7 +193,7 @@ def download(self, collection_id):
return status, information

def install(self, collection_id):
"""Install a collection into QGIS.
"""Install the collection.
:param collection_id: The id of the collection about to be installed.
:type collection_id: str
Expand All @@ -157,12 +206,12 @@ def install(self, collection_id):
COLLECTION_INSTALLED_STATUS

def uninstall(self, collection_id):
"""Uninstall the collection from QGIS.
"""Uninstall the collection.
:param collection_id: The id of the collection about to be uninstalled.
:type collection_id: str
"""
# Uninstall all type of resources from QGIS
# Uninstall all types of resources
for resource_handler in BaseResourceHandler.registry.values():
resource_handler_instance = resource_handler(collection_id)
resource_handler_instance.uninstall()
Expand Down
17 changes: 13 additions & 4 deletions resource_sharing/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# coding=utf-8
"""
# Put the collections object in module namespace
# http://effbot.org/pyfaq/how-do-i-share-global-variables-across-modules.htm
# Put the COLLECTIONS object (dict) in the module namespace
# (http://effbot.org/pyfaq/how-do-i-share-global-variables-across-modules.htm)
Always call this variable as attribute from config module e.g:
Call this variable as an attribute from the config module e.g:
from resource_sharing import config
print config.COLLECTIONS
config.COLLECTIONS is a dict of collection with this structure:
config.COLLECTIONS is a dict that contains metadata for the
collections. It has this structure:
config.COLLECTIONS = {
collection_id(computed): {
'register_name': collection,
Expand All @@ -21,6 +22,14 @@
'description': parser.get(collection, 'description'),
'qgis_min_version': parser.get(collection, 'qgis_minimum_version'),
'qgis_max_version': parser.get(collection, 'qgis_maximum_version')
'preview': ['preview/image1.png', 'preview/image2.png']
# Additional entries (for resource statistics):
'models': count of models in the collection,
'processing': count of processing scripts in the collection,
'rscripts': count of R scripts in the collection,
'style': count of layer styles (QML) in the collection,
'svg': count of SVGs in the collection,
'symbol': count of symbol files (XML) in the collection,
},
....
}
Expand Down
2 changes: 1 addition & 1 deletion resource_sharing/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@


class MetadataError(Exception):
"""Raise when the repository metadata is wrong."""
"""Raise when there is something wrong with the repository metadata."""
pass
Loading

0 comments on commit 2b3d3ac

Please sign in to comment.