From e1a01106ddb97e4f95947cfa40a8ee32b9acab08 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Wed, 22 Mar 2017 19:03:36 +0200 Subject: [PATCH] [processing][API] rename alglist() to printAlgorithms() to improve readability. Also introduce algorithmsList() call which returns available Processing algorithms as list --- python/plugins/processing/tools/general.py | 35 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/python/plugins/processing/tools/general.py b/python/plugins/processing/tools/general.py index f384c0db5c6..98fcb9ecc03 100644 --- a/python/plugins/processing/tools/general.py +++ b/python/plugins/processing/tools/general.py @@ -41,18 +41,38 @@ from processing.core.parameters import ParameterSelection 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)