Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 6510b2f
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 @@ -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))
Expand Down Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py
Expand Up @@ -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
Expand Down Expand Up @@ -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')

Expand Down
22 changes: 22 additions & 0 deletions python/plugins/processing/algs/gdal/GdalUtils.py
Expand Up @@ -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
Expand All @@ -45,6 +47,8 @@

class GdalUtils:

GDAL_HELP_PATH = 'GDAL_HELP_PATH'

supportedRasters = None

@staticmethod
Expand Down Expand Up @@ -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.