Skip to content
Permalink
Browse files

[processing] configurable help files location for GDAL and GRASS prov…

…iders
  • Loading branch information
alexbruy committed Jan 9, 2017
1 parent 3772537 commit 7cda002ba21619392d39030960ec6abf5f086761
@@ -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))
@@ -73,9 +74,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
@@ -99,6 +100,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):
version = GdalUtils.readableVersion()
return 'GDAL ({})'.format(version)
@@ -36,8 +36,10 @@

from qgis.PyQt.QtCore import QSettings
from qgis.core import QgsApplication, QgsVectorFileWriter
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
from processing.core.SilentProgress import SilentProgress
from processing.tools.system import isWindows, isMac

try:
from osgeo import gdal
@@ -48,6 +50,8 @@

class GdalUtils(object):

GDAL_HELP_PATH = 'GDAL_HELP_PATH'

supportedRasters = None

@staticmethod
@@ -190,3 +194,21 @@ def version():
@staticmethod
def readableVersion():
return gdal.VersionInfo('RELEASE_NAME')

@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/'
@@ -106,34 +106,14 @@ def getIcon(self):
return self._icon

def help(self):
localDoc = None
html = self.grass7Name + '.html'
if system.isWindows():
# For MS-Windows, use the configured GRASS7 path
localPath = os.path.join(Grass7Utils.grassPath(), 'docs/html', html)
if os.path.exists(localPath):
localDoc = os.path.abspath(localPath)
elif system.isMac():
# For MacOSX official package
localPath = os.path.join('/Applications/GRASS-7.0.app/Contents/MacOS/docs/html', html)
if os.path.exists(localPath):
localDoc = os.path.abspath(localPath)
helpPath = Grass7Utils.grassHelpPath()
if helpPath == '':
return False, None

if os.path.exists(helpPath):
return False, QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.grass7Name))).toString()
else:
# For GNU/Linux distributions
searchPaths = ['/usr/share/doc/grass-doc/html', '/opt/grass/docs/html',
'/usr/share/doc/grass/docs/html']
for path in searchPaths:
localPath = os.path.join(path, html)
if os.path.exists(localPath):
localDoc = os.path.abspath(localPath)

# Found the local documentation
if localDoc:
localDoc = QUrl.fromLocalFile(localDoc).toString()
return False, localDoc

# Return the URL if local doc is not found
return False, 'http://grass.osgeo.org/grass70/manuals/' + self.grass7Name + '.html'
return False, helpPath + '{}.html'.format(self.grass7Name)

def getParameterDescriptions(self):
descs = {}
@@ -61,13 +61,19 @@ def initializeSettings(self):
self.getDescription(),
Grass7Utils.GRASS_LOG_CONSOLE,
self.tr('Log console output'), False))
ProcessingConfig.addSetting(Setting(
self.getDescription(),
Grass7Utils.GRASS_HELP_PATH,
self.tr('Location of GRASS docs'),
Grass7Utils.grassHelpPath()))

def unload(self):
AlgorithmProvider.unload(self)
if isWindows() or isMac():
ProcessingConfig.removeSetting(Grass7Utils.GRASS_FOLDER)
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_COMMANDS)
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_CONSOLE)
ProcessingConfig.removeSetting(Grass7Utils.GRASS_HELP_PATH)

def createAlgsList(self):
self.preloadedAlgs = []
@@ -50,6 +50,7 @@ class Grass7Utils(object):
GRASS_FOLDER = 'GRASS7_FOLDER'
GRASS_LOG_COMMANDS = 'GRASS7_LOG_COMMANDS'
GRASS_LOG_CONSOLE = 'GRASS7_LOG_CONSOLE'
GRASS_HELP_PATH = 'GRASS_HELP_PATH'

sessionRunning = False
sessionLayers = {}
@@ -428,3 +429,27 @@ def writeCommand(output, command):
except TypeError:
# Python 3
output.write(command + '\n')

@staticmethod
def grassHelpPath():
helpPath = ProcessingConfig.getSetting(Grass7Utils.GRASS_HELP_PATH)

if helpPath is None:
if isWindows():
localPath = os.path.join(Grass7Utils.grassPath(), 'docs/html')
if os.path.exists(localPath):
helpPath = os.path.abspath(localPath)
elif isMac():
localPath = '/Applications/GRASS-7.0.app/Contents/MacOS/docs/html'
if os.path.exists(localPath):
helpPath = os.path.abspath(localPath)
else:
searchPaths = ['/usr/share/doc/grass-doc/html',
'/opt/grass/docs/html',
'/usr/share/doc/grass/docs/html']
for path in searchPaths:
if os.path.exists(path):
helpPath = os.path.abspath(path)
break

return helpPath if helpPath is not None else 'http://grass.osgeo.org/grass70/manuals/'

0 comments on commit 7cda002

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