Skip to content
Permalink
Browse files

[processing] make location of GRASS 7 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 6510b2f commit 8dc9c4c9d2a3c78771018525e836e5f69e90ecc4
@@ -104,34 +104,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 = {}
@@ -195,7 +175,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:
@@ -60,13 +60,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 7 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 = []
@@ -47,6 +47,7 @@ class Grass7Utils:
GRASS_FOLDER = 'GRASS7_FOLDER'
GRASS_LOG_COMMANDS = 'GRASS7_LOG_COMMANDS'
GRASS_LOG_CONSOLE = 'GRASS7_LOG_CONSOLE'
GRASS_HELP_PATH = 'GRASS7_HELP_PATH'

sessionRunning = False
sessionLayers = {}
@@ -399,3 +400,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 8dc9c4c

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