Skip to content
Permalink
Browse files
[processing][API] rename alglist() to printAlgorithms() to improve
readability. Also introduce algorithmsList() call which returns
available Processing algorithms as list
  • Loading branch information
alexbruy committed Mar 22, 2017
1 parent c1e6ba0 commit e1a01106ddb97e4f95947cfa40a8ee32b9acab08
Showing with 32 additions and 3 deletions.
  1. +32 −3 python/plugins/processing/tools/general.py
@@ -41,18 +41,38 @@
from processing.gui.Postprocessing import handleAlgorithmResults


def alglist(text=None):
def algorithmsList(text=None):
"""Returns list of all available Processing algorithms or list
of algorithms which names contains given text.
Returned list contains algorithm command-line names.
"""
lst = []
for provider in list(algList.algs.values()):
sortedlist = sorted(list(provider.values()), key=lambda alg: alg.name)
for alg in sortedlist:
if text is None or text.lower() in alg.name.lower():
lst.append(alg.commandLineName())
return lst


def printAlgorithms(text=None):
"""Print list of all available Processing algorithms or list
of algorithms which names contains given text.
Prints algorithms user-friendly names as well as command-line
names.
"""
s = ''
for provider in list(algList.algs.values()):
sortedlist = sorted(list(provider.values()), key=lambda alg: alg.name)
for alg in sortedlist:
if text is None or text.lower() in alg.name.lower():
s += alg.name.ljust(50, '-') + '--->' + alg.commandLineName() \
+ '\n'
s += '{}--->{}\n'.format(alg.name.ljust(50, '-'), alg.commandLineName())
print(s)


def algorithmOptions(name):
"""Prints all algorithm options with their values.
"""
alg = Processing.getAlgorithm(name)
if alg is not None:
opts = ''
@@ -67,6 +87,9 @@ def algorithmOptions(name):


def algorithmHelp(name):
"""Prints algorithm parameters with their types. Also
provides information about options if any.
"""
alg = Processing.getAlgorithm(name)
if alg is not None:
alg = alg.getCopy()
@@ -77,12 +100,18 @@ def algorithmHelp(name):


def runalg(algOrName, *args, **kwargs):
"""Executes given algorithm and returns its outputs as dictionary
object.
"""
alg = Processing.runAlgorithm(algOrName, None, *args, **kwargs)
if alg is not None:
return alg.getOutputValuesAsDictionary()


def runandload(name, *args, **kwargs):
"""Executes given algorithm and load its results into QGIS project
when possible.
"""
return Processing.runAlgorithm(name, handleAlgorithmResults, *args, **kwargs)


0 comments on commit e1a0110

Please sign in to comment.