Skip to content

Commit

Permalink
[processing][API] rename alglist() to printAlgorithms() to improve
Browse files Browse the repository at this point in the history
readability. Also introduce algorithmsList() call which returns
available Processing algorithms as list
  • Loading branch information
alexbruy committed Mar 22, 2017
1 parent c1e6ba0 commit e1a0110
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions python/plugins/processing/tools/general.py
Expand Up @@ -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 = ''
Expand All @@ -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()
Expand All @@ -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)


Expand Down

0 comments on commit e1a0110

Please sign in to comment.