Skip to content

Commit

Permalink
[processing] configurable URL for scripts and models repository
Browse files Browse the repository at this point in the history
This prevents errors when user tries to download scripts and there
is no access to the Internet (e.g. closed networks)
  • Loading branch information
alexbruy committed Jan 13, 2017
1 parent 84d1a65 commit 3fbb673
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
6 changes: 6 additions & 0 deletions python/plugins/processing/core/ProcessingConfig.py
Expand Up @@ -62,6 +62,7 @@ class ProcessingConfig:
DEFAULT_OUTPUT_RASTER_LAYER_EXT = 'DEFAULT_OUTPUT_RASTER_LAYER_EXT'
DEFAULT_OUTPUT_VECTOR_LAYER_EXT = 'DEFAULT_OUTPUT_VECTOR_LAYER_EXT'
SHOW_PROVIDERS_TOOLTIP = "SHOW_PROVIDERS_TOOLTIP"
MODELS_SCRIPTS_REPO = 'MODELS_SCRIPTS_REPO'

settings = {}
settingIcons = {}
Expand Down Expand Up @@ -145,6 +146,11 @@ def initialize():
ProcessingConfig.tr('General'),
ProcessingConfig.RECENT_ALGORITHMS,
ProcessingConfig.tr('Recent algs'), '', hidden=True))
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.MODELS_SCRIPTS_REPO,
ProcessingConfig.tr('Scripts and models repository'),
'https://raw.githubusercontent.com/qgis/QGIS-Processing/master'))
extensions = processing.tools.dataobjects.getSupportedOutputVectorLayerExtensions()
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
Expand Down
32 changes: 28 additions & 4 deletions python/plugins/processing/gui/GetScriptsAndModels.py
Expand Up @@ -33,14 +33,15 @@
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt, QCoreApplication, QUrl
from qgis.PyQt.QtGui import QIcon, QCursor
from qgis.PyQt.QtWidgets import QApplication, QTreeWidgetItem, QPushButton
from qgis.PyQt.QtWidgets import QApplication, QTreeWidgetItem, QPushButton, QMessageBox
from qgis.PyQt.QtNetwork import QNetworkReply, QNetworkRequest

from qgis.utils import iface, show_message_log
from qgis.core import QgsNetworkAccessManager, QgsMessageLog
from qgis.gui import QgsMessageBar

from processing.core.alglist import algList
from processing.core.ProcessingConfig import ProcessingConfig
from processing.gui.ToolboxAction import ToolboxAction
from processing.gui import Help2Html
from processing.gui.Help2Html import getDescription, ALG_DESC, ALG_VERSION, ALG_CREATOR
Expand All @@ -63,6 +64,13 @@ def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'script.png'))

def execute(self):
repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO)
if repoUrl is None or repoUrl == '':
QMessageBox.warning(None,
self.tr('Repository error'),
self.tr('Scripts and models repository is not configured.'))
return

dlg = GetScriptsAndModelsDialog(GetScriptsAndModelsDialog.SCRIPTS)
dlg.exec_()
if dlg.updateProvider:
Expand All @@ -79,6 +87,13 @@ def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'r.svg'))

def execute(self):
repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO)
if repoUrl is None or repoUrl == '':
QMessageBox.warning(None,
self.tr('Repository error'),
self.tr('Scripts and models repository is not configured.'))
return

dlg = GetScriptsAndModelsDialog(GetScriptsAndModelsDialog.RSCRIPTS)
dlg.exec_()
if dlg.updateProvider:
Expand All @@ -95,6 +110,13 @@ def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'model.png'))

def execute(self):
repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO)
if repoUrl is None or repoUrl == '':
QMessageBox.warning(None,
self.tr('Repository error'),
self.tr('Scripts and models repository is not configured.'))
return

dlg = GetScriptsAndModelsDialog(GetScriptsAndModelsDialog.MODELS)
dlg.exec_()
if dlg.updateProvider:
Expand Down Expand Up @@ -127,18 +149,20 @@ def __init__(self, resourceType):
self.setupUi(self)
self.manager = QgsNetworkAccessManager.instance()

repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO)

self.resourceType = resourceType
if self.resourceType == self.MODELS:
self.folder = ModelerUtils.modelsFolders()[0]
self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/models/'
self.urlBase = '{}/models/'.format(repoUrl)
self.icon = QIcon(os.path.join(pluginPath, 'images', 'model.png'))
elif self.resourceType == self.SCRIPTS:
self.folder = ScriptUtils.scriptsFolders()[0]
self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/scripts/'
self.urlBase = '{}/scripts/'.format(repoUrl)
self.icon = QIcon(os.path.join(pluginPath, 'images', 'script.png'))
else:
self.folder = RUtils.RScriptsFolders()[0]
self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/rscripts/'
self.urlBase = '{}/rscripts/'.format(repoUrl)
self.icon = QIcon(os.path.join(pluginPath, 'images', 'r.svg'))

self.lastSelectedItem = None
Expand Down

0 comments on commit 3fbb673

Please sign in to comment.