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 12, 2017
1 parent 2e3fc18 commit 161adae0a1e2b3c25dddca2c08c8b4eea30fc8d2
@@ -87,34 +87,14 @@ def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'grass.svg'))

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 = {}
@@ -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 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 = {}
@@ -393,3 +394,27 @@ def tr(string, context=''):
if context == '':
context = 'Grass7Utils'
return QCoreApplication.translate(context, string)

@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 161adae

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