Skip to content

Commit 8ea5bc3

Browse files
authored
Merge pull request #3971 from alexbruy/processing-help
[processing] configurable help files location for GDAL and GRASS providers
2 parents 3fd27d1 + 7cda002 commit 8ea5bc3

File tree

6 files changed

+87
-31
lines changed

6 files changed

+87
-31
lines changed

python/plugins/processing/algs/gdal/GdalAlgorithm.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
import re
3030

3131
from qgis.PyQt.QtGui import QIcon
32+
from qgis.PyQt.QtCore import QUrl
3233

3334
from processing.core.GeoAlgorithm import GeoAlgorithm
3435
from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
3536
from processing.algs.gdal.GdalUtils import GdalUtils
36-
from processing.tools import dataobjects
37+
from processing.tools import dataobjects, system
3738

3839
pluginPath = os.path.normpath(os.path.join(
3940
os.path.split(os.path.dirname(__file__))[0], os.pardir))
@@ -73,9 +74,18 @@ def processAlgorithm(self, progress):
7374
GdalUtils.runGdal(commands, progress)
7475

7576
def shortHelp(self):
76-
return self._formatHelp('''This algorithm is based on the GDAL %s module.
77-
For more info, see the <a href = 'http://www.gdal.org/%s.html'> module help</a>
78-
''' % (self.commandName(), self.commandName()))
77+
helpPath = GdalUtils.gdalHelpPath()
78+
if helpPath == '':
79+
return
80+
81+
if os.path.exists(helpPath):
82+
url = QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.commandName()))).toString()
83+
else:
84+
url = helpPath + '{}.html'.format(self.commandName())
85+
86+
return self._formatHelp('''This algorithm is based on the GDAL {} module.
87+
For more info, see the <a href={}> module help</a>
88+
'''.format(self.commandName(), url))
7989

8090
def commandName(self):
8191
alg = self.getCopy()

python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from qgis.PyQt.QtGui import QIcon
3030

3131
from processing.core.AlgorithmProvider import AlgorithmProvider
32+
from processing.core.ProcessingConfig import ProcessingConfig, Setting
3233
from .GdalUtils import GdalUtils
3334

3435
from .nearblack import nearblack
@@ -99,6 +100,18 @@ def __init__(self):
99100
AlgorithmProvider.__init__(self)
100101
self.createAlgsList()
101102

103+
def initializeSettings(self):
104+
AlgorithmProvider.initializeSettings(self)
105+
ProcessingConfig.addSetting(Setting(
106+
self.getDescription(),
107+
GdalUtils.GDAL_HELP_PATH,
108+
self.tr('Location of GDAL docs'),
109+
GdalUtils.gdalHelpPath()))
110+
111+
def unload(self):
112+
AlgorithmProvider.unload(self)
113+
ProcessingConfig.removeSetting(GdalUtils.GDAL_HELP_PATH)
114+
102115
def getDescription(self):
103116
version = GdalUtils.readableVersion()
104117
return 'GDAL ({})'.format(version)

python/plugins/processing/algs/gdal/GdalUtils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636

3737
from qgis.PyQt.QtCore import QSettings
3838
from qgis.core import QgsApplication, QgsVectorFileWriter
39+
from processing.core.ProcessingConfig import ProcessingConfig
3940
from processing.core.ProcessingLog import ProcessingLog
4041
from processing.core.SilentProgress import SilentProgress
42+
from processing.tools.system import isWindows, isMac
4143

4244
try:
4345
from osgeo import gdal
@@ -48,6 +50,8 @@
4850

4951
class GdalUtils(object):
5052

53+
GDAL_HELP_PATH = 'GDAL_HELP_PATH'
54+
5155
supportedRasters = None
5256

5357
@staticmethod
@@ -191,3 +195,21 @@ def version():
191195
@staticmethod
192196
def readableVersion():
193197
return gdal.VersionInfo('RELEASE_NAME')
198+
199+
@staticmethod
200+
def gdalHelpPath():
201+
helpPath = ProcessingConfig.getSetting(GdalUtils.GDAL_HELP_PATH)
202+
203+
if helpPath is None:
204+
if isWindows():
205+
pass
206+
elif isMac():
207+
pass
208+
else:
209+
searchPaths = ['/usr/share/doc/libgdal-doc/gdal']
210+
for path in searchPaths:
211+
if os.path.exists(path):
212+
helpPath = os.path.abspath(path)
213+
break
214+
215+
return helpPath if helpPath is not None else 'http://www.gdal.org/'

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

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -106,34 +106,14 @@ def getIcon(self):
106106
return self._icon
107107

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

138118
def getParameterDescriptions(self):
139119
descs = {}

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

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

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

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

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Grass7Utils(object):
5050
GRASS_FOLDER = 'GRASS7_FOLDER'
5151
GRASS_LOG_COMMANDS = 'GRASS7_LOG_COMMANDS'
5252
GRASS_LOG_CONSOLE = 'GRASS7_LOG_CONSOLE'
53+
GRASS_HELP_PATH = 'GRASS_HELP_PATH'
5354

5455
sessionRunning = False
5556
sessionLayers = {}
@@ -426,3 +427,27 @@ def writeCommand(output, command):
426427
except TypeError:
427428
# Python 3
428429
output.write(command + '\n')
430+
431+
@staticmethod
432+
def grassHelpPath():
433+
helpPath = ProcessingConfig.getSetting(Grass7Utils.GRASS_HELP_PATH)
434+
435+
if helpPath is None:
436+
if isWindows():
437+
localPath = os.path.join(Grass7Utils.grassPath(), 'docs/html')
438+
if os.path.exists(localPath):
439+
helpPath = os.path.abspath(localPath)
440+
elif isMac():
441+
localPath = '/Applications/GRASS-7.0.app/Contents/MacOS/docs/html'
442+
if os.path.exists(localPath):
443+
helpPath = os.path.abspath(localPath)
444+
else:
445+
searchPaths = ['/usr/share/doc/grass-doc/html',
446+
'/opt/grass/docs/html',
447+
'/usr/share/doc/grass/docs/html']
448+
for path in searchPaths:
449+
if os.path.exists(path):
450+
helpPath = os.path.abspath(path)
451+
break
452+
453+
return helpPath if helpPath is not None else 'http://grass.osgeo.org/grass70/manuals/'

0 commit comments

Comments
 (0)