Skip to content

Commit

Permalink
[processing] make location of GDAL help files configurable
Browse files Browse the repository at this point in the history
This prevents errors when algorithm help requested and there is no
access to the Internet (e.g. closed networks)
  • Loading branch information
alexbruy committed Jan 12, 2017
1 parent d7f7481 commit 2e3fc18
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
19 changes: 14 additions & 5 deletions python/plugins/processing/algs/gdal/GdalAlgorithm.py
Expand Up @@ -28,11 +28,12 @@
import os

from PyQt4.QtGui import QIcon
from PyQt4.QtCore import QUrl

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
from processing.algs.gdal.GdalUtils import GdalUtils
from processing.tools import dataobjects
from processing.tools import dataobjects, system

pluginPath = os.path.normpath(os.path.join(
os.path.split(os.path.dirname(__file__))[0], os.pardir))
Expand Down Expand Up @@ -64,10 +65,18 @@ def processAlgorithm(self, progress):
GdalUtils.runGdal(commands, progress)

def shortHelp(self):
return self._formatHelp('''This algorithm is based on the GDAL %s module.
For more info, see the <a href = 'http://www.gdal.org/%s.html'> module help</a>
''' % (self.commandName(), self.commandName()))
helpPath = GdalUtils.gdalHelpPath()
if helpPath == '':
return

if os.path.exists(helpPath):
url = QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.commandName()))).toString()
else:
url = helpPath + '{}.html'.format(self.commandName())

return self._formatHelp('''This algorithm is based on the GDAL {} module.
For more info, see the <a href={}> module help</a>
'''.format(self.commandName(), url))

def commandName(self):
alg = self.getCopy()
Expand Down
13 changes: 13 additions & 0 deletions python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py
Expand Up @@ -29,6 +29,7 @@
from PyQt4.QtGui import QIcon

from processing.core.AlgorithmProvider import AlgorithmProvider
from processing.core.ProcessingConfig import ProcessingConfig, Setting
from processing.core.ProcessingLog import ProcessingLog
from GdalUtils import GdalUtils

Expand Down Expand Up @@ -101,6 +102,18 @@ def __init__(self):
AlgorithmProvider.__init__(self)
self.createAlgsList()

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
ProcessingConfig.addSetting(Setting(
self.getDescription(),
GdalUtils.GDAL_HELP_PATH,
self.tr('Location of GDAL docs'),
GdalUtils.gdalHelpPath()))

def unload(self):
AlgorithmProvider.unload(self)
ProcessingConfig.removeSetting(GdalUtils.GDAL_HELP_PATH)

def getDescription(self):
return self.tr('GDAL/OGR')

Expand Down
22 changes: 22 additions & 0 deletions python/plugins/processing/algs/gdal/GdalUtils.py
Expand Up @@ -30,7 +30,9 @@
import platform
from PyQt4.QtCore import QSettings
from qgis.core import QgsApplication, QgsVectorFileWriter
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
from processing.tools.system import isWindows, isMac

try:
from osgeo import gdal
Expand All @@ -41,6 +43,8 @@

class GdalUtils:

GDAL_HELP_PATH = 'GDAL_HELP_PATH'

supportedRasters = None

@staticmethod
Expand Down Expand Up @@ -163,3 +167,21 @@ def escapeAndJoin(strList):
escaped = s
joined += escaped + ' '
return joined.strip()

@staticmethod
def gdalHelpPath():
helpPath = ProcessingConfig.getSetting(GdalUtils.GDAL_HELP_PATH)

if helpPath is None:
if isWindows():
pass
elif isMac():
pass
else:
searchPaths = ['/usr/share/doc/libgdal-doc/gdal']
for path in searchPaths:
if os.path.exists(path):
helpPath = os.path.abspath(path)
break

return helpPath if helpPath is not None else 'http://www.gdal.org/'

0 comments on commit 2e3fc18

Please sign in to comment.