Skip to content

Commit 6510b2f

Browse files
committed
[processing] make location of GDAL help files configurable.
This prevents errors when algorithm help requested and there is no access to the Internet (e.g. closed networks)
1 parent e7f834a commit 6510b2f

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

python/plugins/processing/algs/gdal/GdalAlgorithm.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
import re
3030

3131
from qgis.PyQt.QtGui import QIcon
32+
from qgis.PyQt.QtCore import QUrl
3233

3334
from processing.core.GeoAlgorithm import GeoAlgorithm
3435
from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
3536
from processing.algs.gdal.GdalUtils import GdalUtils
36-
from processing.tools import dataobjects
37+
from processing.tools import dataobjects, system
3738

3839
pluginPath = os.path.normpath(os.path.join(
3940
os.path.split(os.path.dirname(__file__))[0], os.pardir))
@@ -67,10 +68,18 @@ def processAlgorithm(self, progress):
6768
GdalUtils.runGdal(commands, progress)
6869

6970
def shortHelp(self):
70-
return self._formatHelp('''This algorithm is based on the GDAL %s module.
71-
72-
For more info, see the <a href = 'http://www.gdal.org/%s.html'> module help</a>
73-
''' % (self.commandName(), self.commandName()))
71+
helpPath = GdalUtils.gdalHelpPath()
72+
if helpPath == '':
73+
return
74+
75+
if os.path.exists(helpPath):
76+
url = QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.commandName()))).toString()
77+
else:
78+
url = helpPath + '{}.html'.format(self.commandName())
79+
80+
return self._formatHelp('''This algorithm is based on the GDAL {} module.
81+
For more info, see the <a href={}> module help</a>
82+
'''.format(self.commandName(), url))
7483

7584
def commandName(self):
7685
alg = self.getCopy()

python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from qgis.PyQt.QtGui import QIcon
3030

3131
from processing.core.AlgorithmProvider import AlgorithmProvider
32+
from processing.core.ProcessingConfig import ProcessingConfig, Setting
3233
from .GdalUtils import GdalUtils
3334

3435
from .nearblack import nearblack
@@ -98,6 +99,18 @@ def __init__(self):
9899
AlgorithmProvider.__init__(self)
99100
self.createAlgsList()
100101

102+
def initializeSettings(self):
103+
AlgorithmProvider.initializeSettings(self)
104+
ProcessingConfig.addSetting(Setting(
105+
self.getDescription(),
106+
GdalUtils.GDAL_HELP_PATH,
107+
self.tr('Location of GDAL docs'),
108+
GdalUtils.gdalHelpPath()))
109+
110+
def unload(self):
111+
AlgorithmProvider.unload(self)
112+
ProcessingConfig.removeSetting(GdalUtils.GDAL_HELP_PATH)
113+
101114
def getDescription(self):
102115
return self.tr('GDAL/OGR')
103116

python/plugins/processing/algs/gdal/GdalUtils.py

+22
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
from qgis.PyQt.QtCore import QSettings
3535
from qgis.core import QgsApplication, QgsVectorFileWriter
3636
from processing.core.ProcessingLog import ProcessingLog
37+
from processing.core.ProcessingConfig import ProcessingConfig
3738
from processing.core.SilentProgress import SilentProgress
39+
from processing.tools.system import isWindows, isMac
3840

3941
try:
4042
from osgeo import gdal
@@ -45,6 +47,8 @@
4547

4648
class GdalUtils:
4749

50+
GDAL_HELP_PATH = 'GDAL_HELP_PATH'
51+
4852
supportedRasters = None
4953

5054
@staticmethod
@@ -182,3 +186,21 @@ def escapeAndJoin(strList):
182186
@staticmethod
183187
def version():
184188
return int(gdal.VersionInfo('VERSION_NUM'))
189+
190+
@staticmethod
191+
def gdalHelpPath():
192+
helpPath = ProcessingConfig.getSetting(GdalUtils.GDAL_HELP_PATH)
193+
194+
if helpPath is None:
195+
if isWindows():
196+
pass
197+
elif isMac():
198+
pass
199+
else:
200+
searchPaths = ['/usr/share/doc/libgdal-doc/gdal']
201+
for path in searchPaths:
202+
if os.path.exists(path):
203+
helpPath = os.path.abspath(path)
204+
break
205+
206+
return helpPath if helpPath is not None else 'http://www.gdal.org/'

0 commit comments

Comments
 (0)