Skip to content

Commit

Permalink
[processing] make location of GRASS 6 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 161adae commit b003cbe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/plugins/processing/algs/grass/GrassAlgorithm.py
Expand Up @@ -80,7 +80,14 @@ def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'grass.svg'))

def help(self):
return False, 'http://grass.osgeo.org/grass64/manuals/' + self.grassName + '.html'
helpPath = GrassUtils.grassHelpPath()
if helpPath == '':
return False, None

if os.path.exists(helpPath):
return False, QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.grassName))).toString()
else:
return False, helpPath + '{}.html'.format(self.grassName)

def getParameterDescriptions(self):
descs = {}
Expand Down
Expand Up @@ -62,6 +62,11 @@ def initializeSettings(self):
ProcessingConfig.addSetting(Setting(self.getDescription(),
GrassUtils.GRASS_LOG_CONSOLE,
self.tr('Log console output'), False))
ProcessingConfig.addSetting(Setting(
self.getDescription(),
GrassUtils.GRASS_HELP_PATH,
self.tr('Location of GRASS docs'),
GrassUtils.grassHelpPath()))

def unload(self):
AlgorithmProvider.unload(self)
Expand All @@ -70,6 +75,7 @@ def unload(self):
ProcessingConfig.removeSetting(GrassUtils.GRASS_WIN_SHELL)
ProcessingConfig.removeSetting(GrassUtils.GRASS_LOG_COMMANDS)
ProcessingConfig.removeSetting(GrassUtils.GRASS_LOG_CONSOLE)
ProcessingConfig.removeSetting(Grass7Utils.GRASS_HELP_PATH)

def createAlgsList(self):
self.preloadedAlgs = []
Expand Down
25 changes: 25 additions & 0 deletions python/plugins/processing/algs/grass/GrassUtils.py
Expand Up @@ -50,6 +50,7 @@ class GrassUtils:
GRASS_WIN_SHELL = 'GRASS_WIN_SHELL'
GRASS_LOG_COMMANDS = 'GRASS_LOG_COMMANDS'
GRASS_LOG_CONSOLE = 'GRASS_LOG_CONSOLE'
GRASS_HELP_PATH = 'GRASS_HELP_PATH'

sessionRunning = False
sessionLayers = {}
Expand Down Expand Up @@ -410,3 +411,27 @@ def tr(string, context=''):
if context == '':
context = 'GrassUtils'
return QCoreApplication.translate(context, string)

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

if helpPath is None:
if isWindows():
localPath = os.path.join(GrassUtils.grassPath(), 'docs/html')
if os.path.exists(localPath):
helpPath = os.path.abspath(localPath)
elif isMac():
localPath = '/Applications/GRASS-6.4.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/grass64/manuals/'

0 comments on commit b003cbe

Please sign in to comment.