Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] make location of GRASS 6 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 8dc9c4c commit 84d1a65
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
12 changes: 9 additions & 3 deletions python/plugins/processing/algs/grass/GrassAlgorithm.py
Expand Up @@ -96,9 +96,15 @@ def getIcon(self):
self._icon = QIcon(os.path.join(pluginPath, 'images', 'grass.svg'))
return self._icon


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.grass7Name)

def getParameterDescriptions(self):
descs = {}
Expand Down Expand Up @@ -162,7 +168,7 @@ def defineCharacteristicsFromFile(self):
elif isinstance(output, OutputVector):
vectorOutputs += 1
if isinstance(output, OutputHTML):
self.addOutput(OutputFile("rawoutput", output.description +
self.addOutput(OutputFile("rawoutput", output.description +
" (raw output)", "txt"))
line = lines.readline().strip('\n').strip()
except Exception as e:
Expand Down
Expand Up @@ -63,6 +63,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 @@ -71,6 +76,7 @@ def unload(self):
ProcessingConfig.removeSetting(GrassUtils.GRASS_WIN_SHELL)
ProcessingConfig.removeSetting(GrassUtils.GRASS_LOG_COMMANDS)
ProcessingConfig.removeSetting(GrassUtils.GRASS_LOG_CONSOLE)
ProcessingConfig.removeSetting(GrassUtils.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 @@ -412,3 +413,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(Grass7Utils.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 84d1a65

Please sign in to comment.