Skip to content

Commit 8dc9c4c

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

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed
 

‎python/plugins/processing/algs/grass7/Grass7Algorithm.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -104,34 +104,14 @@ def getIcon(self):
104104
return self._icon
105105

106106
def help(self):
107-
localDoc = None
108-
html = self.grass7Name + '.html'
109-
if system.isWindows():
110-
# For MS-Windows, use the configured GRASS7 path
111-
localPath = os.path.join(Grass7Utils.grassPath(), 'docs/html', html)
112-
if os.path.exists(localPath):
113-
localDoc = os.path.abspath(localPath)
114-
elif system.isMac():
115-
# For MacOSX official package
116-
localPath = os.path.join('/Applications/GRASS-7.0.app/Contents/MacOS/docs/html', html)
117-
if os.path.exists(localPath):
118-
localDoc = os.path.abspath(localPath)
107+
helpPath = Grass7Utils.grassHelpPath()
108+
if helpPath == '':
109+
return False, None
110+
111+
if os.path.exists(helpPath):
112+
return False, QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.grass7Name))).toString()
119113
else:
120-
# For GNU/Linux distributions
121-
searchPaths = ['/usr/share/doc/grass-doc/html', '/opt/grass/docs/html',
122-
'/usr/share/doc/grass/docs/html']
123-
for path in searchPaths:
124-
localPath = os.path.join(path, html)
125-
if os.path.exists(localPath):
126-
localDoc = os.path.abspath(localPath)
127-
128-
# Found the local documentation
129-
if localDoc:
130-
localDoc = QUrl.fromLocalFile(localDoc).toString()
131-
return False, localDoc
132-
133-
# Return the URL if local doc is not found
134-
return False, 'http://grass.osgeo.org/grass70/manuals/' + self.grass7Name + '.html'
114+
return False, helpPath + '{}.html'.format(self.grass7Name)
135115

136116
def getParameterDescriptions(self):
137117
descs = {}
@@ -195,7 +175,7 @@ def defineCharacteristicsFromFile(self):
195175
elif isinstance(output, OutputVector):
196176
vectorOutputs += 1
197177
if isinstance(output, OutputHTML):
198-
self.addOutput(OutputFile("rawoutput", output.description +
178+
self.addOutput(OutputFile("rawoutput", output.description +
199179
" (raw output)", "txt"))
200180
line = lines.readline().strip('\n').strip()
201181
except Exception as e:

‎python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,19 @@ def initializeSettings(self):
6060
self.getDescription(),
6161
Grass7Utils.GRASS_LOG_CONSOLE,
6262
self.tr('Log console output'), False))
63+
ProcessingConfig.addSetting(Setting(
64+
self.getDescription(),
65+
Grass7Utils.GRASS_HELP_PATH,
66+
self.tr('Location of GRASS 7 docs'),
67+
Grass7Utils.grassHelpPath()))
6368

6469
def unload(self):
6570
AlgorithmProvider.unload(self)
6671
if isWindows() or isMac():
6772
ProcessingConfig.removeSetting(Grass7Utils.GRASS_FOLDER)
6873
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_COMMANDS)
6974
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_CONSOLE)
75+
ProcessingConfig.removeSetting(Grass7Utils.GRASS_HELP_PATH)
7076

7177
def createAlgsList(self):
7278
self.preloadedAlgs = []

‎python/plugins/processing/algs/grass7/Grass7Utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Grass7Utils:
4747
GRASS_FOLDER = 'GRASS7_FOLDER'
4848
GRASS_LOG_COMMANDS = 'GRASS7_LOG_COMMANDS'
4949
GRASS_LOG_CONSOLE = 'GRASS7_LOG_CONSOLE'
50+
GRASS_HELP_PATH = 'GRASS7_HELP_PATH'
5051

5152
sessionRunning = False
5253
sessionLayers = {}
@@ -399,3 +400,27 @@ def writeCommand(output, command):
399400
except TypeError:
400401
# Python 3
401402
output.write(command + '\n')
403+
404+
@staticmethod
405+
def grassHelpPath():
406+
helpPath = ProcessingConfig.getSetting(Grass7Utils.GRASS_HELP_PATH)
407+
408+
if helpPath is None:
409+
if isWindows():
410+
localPath = os.path.join(Grass7Utils.grassPath(), 'docs/html')
411+
if os.path.exists(localPath):
412+
helpPath = os.path.abspath(localPath)
413+
elif isMac():
414+
localPath = '/Applications/GRASS-7.0.app/Contents/MacOS/docs/html'
415+
if os.path.exists(localPath):
416+
helpPath = os.path.abspath(localPath)
417+
else:
418+
searchPaths = ['/usr/share/doc/grass-doc/html',
419+
'/opt/grass/docs/html',
420+
'/usr/share/doc/grass/docs/html']
421+
for path in searchPaths:
422+
if os.path.exists(path):
423+
helpPath = os.path.abspath(path)
424+
break
425+
426+
return helpPath if helpPath is not None else 'http://grass.osgeo.org/grass70/manuals/'

0 commit comments

Comments
 (0)
Please sign in to comment.