Skip to content
Permalink
Browse files

[processing] configurable URL for scripts and models repository

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 12, 2017
1 parent b003cbe commit 75025ed19aafb708ffd9b4dd65726d367963a4ac
@@ -53,6 +53,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 = {}
@@ -132,6 +133,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'),
@@ -32,13 +32,14 @@

from PyQt4 import uic
from PyQt4.QtCore import Qt, QCoreApplication, QUrl
from PyQt4.QtGui import QIcon, QCursor, QApplication, QTreeWidgetItem, QPushButton
from PyQt4.QtGui import QIcon, QCursor, QApplication, QTreeWidgetItem, QPushButton, QMessageBox
from PyQt4.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.ProcessingConfig import ProcessingConfig
from processing.gui.ToolboxAction import ToolboxAction
from processing.script.ScriptUtils import ScriptUtils
from processing.algs.r.RUtils import RUtils
@@ -61,6 +62,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.updateToolbox:
@@ -77,6 +85,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.updateToolbox:
@@ -93,6 +108,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.updateToolbox:
@@ -125,18 +147,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.modelsFolder()
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.scriptsFolder()
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.RScriptsFolder()
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

0 comments on commit 75025ed

Please sign in to comment.
You can’t perform that action at this time.