Skip to content

Commit

Permalink
[processing] load documentation from online QGIS User Guide
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Dec 7, 2014
1 parent a6fcb3a commit fc6ad27
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
51 changes: 37 additions & 14 deletions python/plugins/processing/core/GeoAlgorithm.py
Expand Up @@ -107,25 +107,48 @@ def getDefaultIcon():

def help(self):
"""Returns the help with the description of this algorithm.
It returns a tuple boolean, string. IF the boolean value is true, it means that
the string contains the actual description. If false, it is an url or path to a file
where the description is stored. In both cases, the string or the content of the file
have to be HTML, ready to be set into the help display component.
It returns a tuple boolean, string. IF the boolean value is True,
it means that the string contains the actual description. If False,
it is an url or path to a file where the description is stored.
In both cases, the string or the content of the file have to be HTML,
ready to be set into the help display component.
Returns None if there is no help file available.
The default implementation looks for an rst file in a help folder under the folder
where the algorithm is located.
The name of the file is the name console name of the algorithm, without the namespace part
The default implementation looks for an HTML page in the QGIS
documentation site taking into account QGIS version.
"""
name = self.commandLineName().split(':')[1].lower()
filename = os.path.join(os.path.dirname(inspect.getfile(self.__class__)), 'help', name + '.rst')
try:
html = getHtmlFromRstFile(filename)
return True, html
except:
return False, None

qgsVersion = QGis.QGIS_VERSION_INT
major = qgsVersion / 10000
minor = minor = (qgsVersion - major * 10000) / 100
if minor % 2 == 1:
qgsVersion = 'testing'
else:
qgsVersion = '{}.{}'.format(major, minor)

providerName = self.provider.getName().lower()
groupName = self.group.lower()
groupName = groupName.replace('[', '').replace(']', '').replace(' - ', '_')
groupName = groupName.replace(' ', '_')
cmdLineName = self.commandLineName()
algName = cmdLineName[cmdLineName.find(':') + 1:].lower()
validChars = \
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
safeGroupName = ''.join(c for c in groupName if c in validChars)
safeAlgName = ''.join(c for c in algName if c in validChars)

helpUrl = 'http://docs.qgis.org/{}/en/docs/user_manual/processing_algs/{}/{}/{}.html'.format(qgsVersion, providerName, safeGroupName, safeAlgName)
print 'HELP', helpUrl
return False, helpUrl

#name = self.commandLineName().split(':')[1].lower()
#filename = os.path.join(os.path.dirname(inspect.getfile(self.__class__)), 'help', name + '.rst')
#try:
#html = getHtmlFromRstFile(filename)
#return True, html
#except:
#return False, None

def processAlgorithm(self):
"""Here goes the algorithm itself.
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/core/outputs.py
Expand Up @@ -60,7 +60,7 @@ def __init__(self, name='', description='', hidden=False):
self.open = True

def __str__(self):
return self.name + ' <' + self.__class__.__name__ + '>'
return u'{} <{}>'.format(self.name, self.__class__.__name__)

def getValueAsCommandLineParameter(self):
if self.value is None:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/core/parameters.py
Expand Up @@ -75,7 +75,7 @@ def setValue(self, obj):
return True

def __str__(self):
return self.name + ' <' + self.__module__.split('.')[-1] + '>'
return u'{} <{}>'.format(self.name, self.__class__.__name__)

def getValueAsCommandLineParameter(self):
"""
Expand Down

0 comments on commit fc6ad27

Please sign in to comment.