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 13, 2017
1 parent e7f834a commit 6510b2fa8c4686f8ae1d3d35af0f215d1217f31d
@@ -29,11 +29,12 @@
import re

from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.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))
@@ -67,10 +68,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 qgis.PyQt.QtGui import QIcon

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

from .nearblack import nearblack
@@ -98,6 +99,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')

@@ -34,7 +34,9 @@
from qgis.PyQt.QtCore import QSettings
from qgis.core import QgsApplication, QgsVectorFileWriter
from processing.core.ProcessingLog import ProcessingLog
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.SilentProgress import SilentProgress
from processing.tools.system import isWindows, isMac

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

class GdalUtils:

GDAL_HELP_PATH = 'GDAL_HELP_PATH'

supportedRasters = None

@staticmethod
@@ -182,3 +186,21 @@ def escapeAndJoin(strList):
@staticmethod
def version():
return int(gdal.VersionInfo('VERSION_NUM'))

@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 6510b2f

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