Skip to content

Commit 84d1a65

Browse files
committedJan 13, 2017
[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)
1 parent 8dc9c4c commit 84d1a65

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed
 

‎python/plugins/processing/algs/grass/GrassAlgorithm.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,15 @@ def getIcon(self):
9696
self._icon = QIcon(os.path.join(pluginPath, 'images', 'grass.svg'))
9797
return self._icon
9898

99-
10099
def help(self):
101-
return False, 'http://grass.osgeo.org/grass64/manuals/' + self.grassName + '.html'
100+
helpPath = GrassUtils.grassHelpPath()
101+
if helpPath == '':
102+
return False, None
103+
104+
if os.path.exists(helpPath):
105+
return False, QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.grassName))).toString()
106+
else:
107+
return False, helpPath + '{}.html'.format(self.grass7Name)
102108

103109
def getParameterDescriptions(self):
104110
descs = {}
@@ -162,7 +168,7 @@ def defineCharacteristicsFromFile(self):
162168
elif isinstance(output, OutputVector):
163169
vectorOutputs += 1
164170
if isinstance(output, OutputHTML):
165-
self.addOutput(OutputFile("rawoutput", output.description +
171+
self.addOutput(OutputFile("rawoutput", output.description +
166172
" (raw output)", "txt"))
167173
line = lines.readline().strip('\n').strip()
168174
except Exception as e:

‎python/plugins/processing/algs/grass/GrassAlgorithmProvider.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def initializeSettings(self):
6363
ProcessingConfig.addSetting(Setting(self.getDescription(),
6464
GrassUtils.GRASS_LOG_CONSOLE,
6565
self.tr('Log console output'), False))
66+
ProcessingConfig.addSetting(Setting(
67+
self.getDescription(),
68+
GrassUtils.GRASS_HELP_PATH,
69+
self.tr('Location of GRASS docs'),
70+
GrassUtils.grassHelpPath()))
6671

6772
def unload(self):
6873
AlgorithmProvider.unload(self)
@@ -71,6 +76,7 @@ def unload(self):
7176
ProcessingConfig.removeSetting(GrassUtils.GRASS_WIN_SHELL)
7277
ProcessingConfig.removeSetting(GrassUtils.GRASS_LOG_COMMANDS)
7378
ProcessingConfig.removeSetting(GrassUtils.GRASS_LOG_CONSOLE)
79+
ProcessingConfig.removeSetting(GrassUtils.GRASS_HELP_PATH)
7480

7581
def createAlgsList(self):
7682
self.preloadedAlgs = []

‎python/plugins/processing/algs/grass/GrassUtils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class GrassUtils:
5050
GRASS_WIN_SHELL = 'GRASS_WIN_SHELL'
5151
GRASS_LOG_COMMANDS = 'GRASS_LOG_COMMANDS'
5252
GRASS_LOG_CONSOLE = 'GRASS_LOG_CONSOLE'
53+
GRASS_HELP_PATH = 'GRASS_HELP_PATH'
5354

5455
sessionRunning = False
5556
sessionLayers = {}
@@ -412,3 +413,27 @@ def tr(string, context=''):
412413
if context == '':
413414
context = 'GrassUtils'
414415
return QCoreApplication.translate(context, string)
416+
417+
@staticmethod
418+
def grassHelpPath():
419+
helpPath = ProcessingConfig.getSetting(GrassUtils.GRASS_HELP_PATH)
420+
421+
if helpPath is None:
422+
if isWindows():
423+
localPath = os.path.join(Grass7Utils.grassPath(), 'docs/html')
424+
if os.path.exists(localPath):
425+
helpPath = os.path.abspath(localPath)
426+
elif isMac():
427+
localPath = '/Applications/GRASS-6.4.app/Contents/MacOS/docs/html'
428+
if os.path.exists(localPath):
429+
helpPath = os.path.abspath(localPath)
430+
else:
431+
searchPaths = ['/usr/share/doc/grass-doc/html',
432+
'/opt/grass/docs/html',
433+
'/usr/share/doc/grass/docs/html']
434+
for path in searchPaths:
435+
if os.path.exists(path):
436+
helpPath = os.path.abspath(path)
437+
break
438+
439+
return helpPath if helpPath is not None else 'http://grass.osgeo.org/grass64/manuals/'

0 commit comments

Comments
 (0)
Please sign in to comment.