Skip to content

Commit 75025ed

Browse files
committed
[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)
1 parent b003cbe commit 75025ed

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎python/plugins/processing/core/ProcessingConfig.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ProcessingConfig:
5353
DEFAULT_OUTPUT_RASTER_LAYER_EXT = 'DEFAULT_OUTPUT_RASTER_LAYER_EXT'
5454
DEFAULT_OUTPUT_VECTOR_LAYER_EXT = 'DEFAULT_OUTPUT_VECTOR_LAYER_EXT'
5555
SHOW_PROVIDERS_TOOLTIP = "SHOW_PROVIDERS_TOOLTIP"
56+
MODELS_SCRIPTS_REPO = 'MODELS_SCRIPTS_REPO'
5657

5758
settings = {}
5859
settingIcons = {}
@@ -132,6 +133,11 @@ def initialize():
132133
ProcessingConfig.tr('General'),
133134
ProcessingConfig.RECENT_ALGORITHMS,
134135
ProcessingConfig.tr('Recent algs'), '', hidden=True))
136+
ProcessingConfig.addSetting(Setting(
137+
ProcessingConfig.tr('General'),
138+
ProcessingConfig.MODELS_SCRIPTS_REPO,
139+
ProcessingConfig.tr('Scripts and models repository'),
140+
'https://raw.githubusercontent.com/qgis/QGIS-Processing/master'))
135141
extensions = processing.tools.dataobjects.getSupportedOutputVectorLayerExtensions()
136142
ProcessingConfig.addSetting(Setting(
137143
ProcessingConfig.tr('General'),

‎python/plugins/processing/gui/GetScriptsAndModels.py‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232

3333
from PyQt4 import uic
3434
from PyQt4.QtCore import Qt, QCoreApplication, QUrl
35-
from PyQt4.QtGui import QIcon, QCursor, QApplication, QTreeWidgetItem, QPushButton
35+
from PyQt4.QtGui import QIcon, QCursor, QApplication, QTreeWidgetItem, QPushButton, QMessageBox
3636
from PyQt4.QtNetwork import QNetworkReply, QNetworkRequest
3737

3838
from qgis.utils import iface, show_message_log
3939
from qgis.core import QgsNetworkAccessManager, QgsMessageLog
4040
from qgis.gui import QgsMessageBar
4141

42+
from processing.core.ProcessingConfig import ProcessingConfig
4243
from processing.gui.ToolboxAction import ToolboxAction
4344
from processing.script.ScriptUtils import ScriptUtils
4445
from processing.algs.r.RUtils import RUtils
@@ -61,6 +62,13 @@ def getIcon(self):
6162
return QIcon(os.path.join(pluginPath, 'images', 'script.png'))
6263

6364
def execute(self):
65+
repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO)
66+
if repoUrl is None or repoUrl == '':
67+
QMessageBox.warning(None,
68+
self.tr('Repository error'),
69+
self.tr('Scripts and models repository is not configured.'))
70+
return
71+
6472
dlg = GetScriptsAndModelsDialog(GetScriptsAndModelsDialog.SCRIPTS)
6573
dlg.exec_()
6674
if dlg.updateToolbox:
@@ -77,6 +85,13 @@ def getIcon(self):
7785
return QIcon(os.path.join(pluginPath, 'images', 'r.svg'))
7886

7987
def execute(self):
88+
repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO)
89+
if repoUrl is None or repoUrl == '':
90+
QMessageBox.warning(None,
91+
self.tr('Repository error'),
92+
self.tr('Scripts and models repository is not configured.'))
93+
return
94+
8095
dlg = GetScriptsAndModelsDialog(GetScriptsAndModelsDialog.RSCRIPTS)
8196
dlg.exec_()
8297
if dlg.updateToolbox:
@@ -93,6 +108,13 @@ def getIcon(self):
93108
return QIcon(os.path.join(pluginPath, 'images', 'model.png'))
94109

95110
def execute(self):
111+
repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO)
112+
if repoUrl is None or repoUrl == '':
113+
QMessageBox.warning(None,
114+
self.tr('Repository error'),
115+
self.tr('Scripts and models repository is not configured.'))
116+
return
117+
96118
dlg = GetScriptsAndModelsDialog(GetScriptsAndModelsDialog.MODELS)
97119
dlg.exec_()
98120
if dlg.updateToolbox:
@@ -125,18 +147,20 @@ def __init__(self, resourceType):
125147
self.setupUi(self)
126148
self.manager = QgsNetworkAccessManager.instance()
127149

150+
repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO)
151+
128152
self.resourceType = resourceType
129153
if self.resourceType == self.MODELS:
130154
self.folder = ModelerUtils.modelsFolder()
131-
self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/models/'
155+
self.urlBase = '{}/models/'.format(repoUrl)
132156
self.icon = QIcon(os.path.join(pluginPath, 'images', 'model.png'))
133157
elif self.resourceType == self.SCRIPTS:
134158
self.folder = ScriptUtils.scriptsFolder()
135-
self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/scripts/'
159+
self.urlBase = '{}/scripts/'.format(repoUrl)
136160
self.icon = QIcon(os.path.join(pluginPath, 'images', 'script.png'))
137161
else:
138162
self.folder = RUtils.RScriptsFolder()
139-
self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/rscripts/'
163+
self.urlBase = '{}/rscripts/'.format(repoUrl)
140164
self.icon = QIcon(os.path.join(pluginPath, 'images', 'r.svg'))
141165

142166
self.lastSelectedItem = None

0 commit comments

Comments
 (0)