[processing] load documentation from online QGIS User Guide

This commit is contained in:
Alexander Bruy 2014-12-07 12:50:54 +02:00
parent a6fcb3a412
commit fc6ad27db8
3 changed files with 39 additions and 16 deletions

View File

@ -107,25 +107,48 @@ class GeoAlgorithm:
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.

View File

@ -60,7 +60,7 @@ class Output(object):
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:

View File

@ -75,7 +75,7 @@ class Parameter:
return True
def __str__(self):
return self.name + ' <' + self.__module__.split('.')[-1] + '>'
return u'{} <{}>'.format(self.name, self.__class__.__name__)
def getValueAsCommandLineParameter(self):
"""