Skip to content
Permalink
Browse files

[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)
  • Loading branch information
alexbruy committed Jan 12, 2017
1 parent d7f7481 commit 2e3fc184978d6286029f5bb3fcd4e0ca3e4d8c1c
@@ -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))
@@ -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()
@@ -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

@@ -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')

@@ -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
@@ -41,6 +43,8 @@

class GdalUtils:

GDAL_HELP_PATH = 'GDAL_HELP_PATH'

supportedRasters = None

@staticmethod
@@ -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.
You can’t perform that action at this time.