Skip to content

Commit e1a0110

Browse files
committedMar 22, 2017
[processing][API] rename alglist() to printAlgorithms() to improve
readability. Also introduce algorithmsList() call which returns available Processing algorithms as list
1 parent c1e6ba0 commit e1a0110

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed
 

‎python/plugins/processing/tools/general.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,38 @@
4141
from processing.gui.Postprocessing import handleAlgorithmResults
4242

4343

44-
def alglist(text=None):
44+
def algorithmsList(text=None):
45+
"""Returns list of all available Processing algorithms or list
46+
of algorithms which names contains given text.
47+
Returned list contains algorithm command-line names.
48+
"""
49+
lst = []
50+
for provider in list(algList.algs.values()):
51+
sortedlist = sorted(list(provider.values()), key=lambda alg: alg.name)
52+
for alg in sortedlist:
53+
if text is None or text.lower() in alg.name.lower():
54+
lst.append(alg.commandLineName())
55+
return lst
56+
57+
58+
def printAlgorithms(text=None):
59+
"""Print list of all available Processing algorithms or list
60+
of algorithms which names contains given text.
61+
Prints algorithms user-friendly names as well as command-line
62+
names.
63+
"""
4564
s = ''
4665
for provider in list(algList.algs.values()):
4766
sortedlist = sorted(list(provider.values()), key=lambda alg: alg.name)
4867
for alg in sortedlist:
4968
if text is None or text.lower() in alg.name.lower():
50-
s += alg.name.ljust(50, '-') + '--->' + alg.commandLineName() \
51-
+ '\n'
69+
s += '{}--->{}\n'.format(alg.name.ljust(50, '-'), alg.commandLineName())
5270
print(s)
5371

5472

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

6888

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

78101

79102
def runalg(algOrName, *args, **kwargs):
103+
"""Executes given algorithm and returns its outputs as dictionary
104+
object.
105+
"""
80106
alg = Processing.runAlgorithm(algOrName, None, *args, **kwargs)
81107
if alg is not None:
82108
return alg.getOutputValuesAsDictionary()
83109

84110

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

88117

0 commit comments

Comments
 (0)
Please sign in to comment.