Skip to content
Browse files

Update for new API

  • Loading branch information
nyalldawson committed Jun 27, 2017
1 parent 14347a4 commit f98bcb2b81131f6e359bc54e864e0b650404458f
Showing with 26 additions and 22 deletions.
  1. +24 −20 python/plugins/processing/core/
  2. +2 −2 python/plugins/processing/tools/
@@ -51,6 +51,7 @@
from processing.gui.Postprocessing import handleAlgorithmResults
from processing.gui.AlgorithmExecutor import execute
from import dataobjects
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider # NOQA
#from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider # NOQA
@@ -122,31 +123,31 @@ def removeScripts(folder):

def runAlgorithm(algOrName, parameters, onFinish, feedback=None, context=None):
def runAlgorithm(algOrName, parameters, onFinish=None, feedback=None, context=None):
if isinstance(algOrName, QgsProcessingAlgorithm):
alg = algOrName
alg = QgsApplication.processingRegistry().algorithmById(algOrName)

if feedback is None:
feedback = MessageBarProgress(alg.displayName() if alg else'Processing'))

if alg is None:
# fix_print_with_import
print('Error: Algorithm not found\n')
QgsMessageLog.logMessage('Error: Algorithm {0} not found\n').format(algOrName),"Processing"))
msg ='Error: Algorithm {0} not found\n').format(algOrName)
raise GeoAlgorithmExecutionException(msg)

# check for any manadatory parameters which were not specified
# check for any mandatory parameters which were not specified
for param in alg.parameterDefinitions():
if not in parameters:
if not param.flags() & QgsProcessingParameterDefinition.FlagOptional:
# fix_print_with_import
msg ='Error: Missing parameter value for parameter {0}.').format(
print('Error: Missing parameter value for parameter %s.' %
QgsMessageLog.logMessage('Error: Missing parameter value for parameter {0}.').format(,"Processing"))

if feedback is None:
feedback = MessageBarProgress(alg.displayName())
raise GeoAlgorithmExecutionException(msg)

if context is None:
context = dataobjects.createContext(feedback)
@@ -155,24 +156,27 @@ def runAlgorithm(algOrName, parameters, onFinish, feedback=None, context=None):
if not ok:
# fix_print_with_import
print('Unable to execute algorithm\n' + str(msg))
QgsMessageLog.logMessage('Unable to execute algorithm\n{0}').format(msg),"Processing"))
msg ='Unable to execute algorithm\n{0}').format(msg)
raise GeoAlgorithmExecutionException(msg)

if not alg.validateInputCrs(parameters, context):
print('Warning: Not all input layers use the same CRS.\n' +
'This can cause unexpected results.')
QgsMessageLog.logMessage('Warning: Not all input layers use the same CRS.\nThis can cause unexpected results.'),"Processing"))
feedback.pushInfo('Warning: Not all input layers use the same CRS.\nThis can cause unexpected results.'))

ret, results = execute(alg, parameters, context, feedback)
if ret:
feedback.pushInfo('Results: {}').format(results))

if onFinish is not None:
onFinish(alg, context, feedback)
QgsMessageLog.logMessage("There were errors executing the algorithm."),"Processing"))
msg ="There were errors executing the algorithm.")
raise GeoAlgorithmExecutionException(msg)

if isinstance(feedback, MessageBarProgress):
@@ -69,11 +69,11 @@ def algorithmHelp(id):
print('Algorithm "{}" not found.'.format(id))

def run(algOrName, *args, **kwargs):
def run(algOrName, parameters, onFinish=None, feedback=None, context=None):
"""Executes given algorithm and returns its outputs as dictionary
return Processing.runAlgorithm(algOrName, None, *args, **kwargs)
return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)

def runAndLoadResults(name, *args, **kwargs):

0 comments on commit f98bcb2

Please sign in to comment.
You can’t perform that action at this time.