mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-19 00:04:52 -04:00
[processing] remove GeoAlgorithmExecutionException
This commit is contained in:
parent
97a5a3dcbd
commit
56208540f9
@ -40,12 +40,12 @@ from qgis.core import (QgsProcessingFeedback,
|
|||||||
QgsProcessingAlgorithm,
|
QgsProcessingAlgorithm,
|
||||||
QgsProject,
|
QgsProject,
|
||||||
QgsProcessingUtils,
|
QgsProcessingUtils,
|
||||||
|
QgsProcessingException,
|
||||||
QgsProcessingParameterDefinition,
|
QgsProcessingParameterDefinition,
|
||||||
QgsMessageLog)
|
QgsMessageLog)
|
||||||
from qgis.gui import QgsHelp
|
from qgis.gui import QgsHelp
|
||||||
|
|
||||||
from processing.core.ProcessingConfig import ProcessingConfig
|
from processing.core.ProcessingConfig import ProcessingConfig
|
||||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
|
||||||
from processing.core.parameters import ParameterRaster, ParameterVector, ParameterMultipleInput, ParameterTable, Parameter
|
from processing.core.parameters import ParameterRaster, ParameterVector, ParameterMultipleInput, ParameterTable, Parameter
|
||||||
from processing.core.outputs import OutputVector, OutputRaster, OutputTable, OutputHTML, Output
|
from processing.core.outputs import OutputVector, OutputRaster, OutputTable, OutputHTML, Output
|
||||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||||
@ -76,7 +76,7 @@ class GeoAlgorithm(QgsProcessingAlgorithm):
|
|||||||
"""Here goes the algorithm itself.
|
"""Here goes the algorithm itself.
|
||||||
|
|
||||||
There is no return value from this method.
|
There is no return value from this method.
|
||||||
A GeoAlgorithmExecutionException should be raised in case
|
A QgsProcessingException should be raised in case
|
||||||
something goes wrong.
|
something goes wrong.
|
||||||
:param parameters:
|
:param parameters:
|
||||||
:param context:
|
:param context:
|
||||||
@ -105,7 +105,7 @@ class GeoAlgorithm(QgsProcessingAlgorithm):
|
|||||||
it should be called using this method, since it performs
|
it should be called using this method, since it performs
|
||||||
some additional operations.
|
some additional operations.
|
||||||
|
|
||||||
Raises a GeoAlgorithmExecutionException in case anything goes
|
Raises a QgsProcessingException in case anything goes
|
||||||
wrong.
|
wrong.
|
||||||
:param parameters:
|
:param parameters:
|
||||||
"""
|
"""
|
||||||
@ -124,18 +124,18 @@ class GeoAlgorithm(QgsProcessingAlgorithm):
|
|||||||
feedback.setProgress(100)
|
feedback.setProgress(100)
|
||||||
self.convertUnsupportedFormats(context, feedback)
|
self.convertUnsupportedFormats(context, feedback)
|
||||||
self.runPostExecutionScript(feedback)
|
self.runPostExecutionScript(feedback)
|
||||||
except GeoAlgorithmExecutionException as gaee:
|
except QgsProcessingException as gaee:
|
||||||
lines = [self.tr('Error while executing algorithm')]
|
lines = [self.tr('Error while executing algorithm')]
|
||||||
lines.append(traceback.format_exc())
|
lines.append(traceback.format_exc())
|
||||||
QgsMessageLog.logMessage(gaee.msg, self.tr('Processing'), QgsMessageLog.CRITICAL)
|
QgsMessageLog.logMessage(gaee.msg, self.tr('Processing'), QgsMessageLog.CRITICAL)
|
||||||
raise GeoAlgorithmExecutionException(gaee.msg, lines, gaee)
|
raise QgsProcessingException(gaee.msg, lines, gaee)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# If something goes wrong and is not caught in the
|
# If something goes wrong and is not caught in the
|
||||||
# algorithm, we catch it here and wrap it
|
# algorithm, we catch it here and wrap it
|
||||||
lines = [self.tr('Uncaught error while executing algorithm')]
|
lines = [self.tr('Uncaught error while executing algorithm')]
|
||||||
lines.append(traceback.format_exc())
|
lines.append(traceback.format_exc())
|
||||||
QgsMessageLog.logMessage('\n'.join(lines), self.tr('Processing'), QgsMessageLog.CRITICAL)
|
QgsMessageLog.logMessage('\n'.join(lines), self.tr('Processing'), QgsMessageLog.CRITICAL)
|
||||||
raise GeoAlgorithmExecutionException(str(e) + self.tr('\nSee log for more details'), lines, e)
|
raise QgsProcessingException(str(e) + self.tr('\nSee log for more details'), lines, e)
|
||||||
|
|
||||||
def runPostExecutionScript(self, feedback):
|
def runPostExecutionScript(self, feedback):
|
||||||
scriptFile = ProcessingConfig.getSetting(
|
scriptFile = ProcessingConfig.getSetting(
|
||||||
@ -235,7 +235,7 @@ class GeoAlgorithm(QgsProcessingAlgorithm):
|
|||||||
for out in self.outputs:
|
for out in self.outputs:
|
||||||
out.resolveValue(self)
|
out.resolveValue(self)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise GeoAlgorithmExecutionException(str(e))
|
raise QgsProcessingException(str(e))
|
||||||
|
|
||||||
def setOutputCRS(self):
|
def setOutputCRS(self):
|
||||||
context = dataobjects.createContext()
|
context = dataobjects.createContext()
|
||||||
@ -319,7 +319,7 @@ def executeAlgorithm(alg, parameters, context=None, feedback=None, model=None):
|
|||||||
it should be called using this method, since it performs
|
it should be called using this method, since it performs
|
||||||
some additional operations.
|
some additional operations.
|
||||||
|
|
||||||
Raises a GeoAlgorithmExecutionException in case anything goes
|
Raises a QgsProcessingException in case anything goes
|
||||||
wrong.
|
wrong.
|
||||||
:param parameters:
|
:param parameters:
|
||||||
"""
|
"""
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
|
||||||
***************************************************************************
|
|
||||||
GeoAlgorithmExecutionException.py
|
|
||||||
---------------------
|
|
||||||
Date : August 2012
|
|
||||||
Copyright : (C) 2012 by Victor Olaya
|
|
||||||
Email : volayaf at gmail dot com
|
|
||||||
***************************************************************************
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
***************************************************************************
|
|
||||||
"""
|
|
||||||
|
|
||||||
__author__ = 'Victor Olaya'
|
|
||||||
__date__ = 'August 2012'
|
|
||||||
__copyright__ = '(C) 2012, Victor Olaya'
|
|
||||||
|
|
||||||
# This will get replaced with a git SHA1 when you do a git archive
|
|
||||||
|
|
||||||
__revision__ = '$Format:%H$'
|
|
||||||
|
|
||||||
|
|
||||||
class GeoAlgorithmExecutionException(Exception):
|
|
||||||
|
|
||||||
def __init__(self, msg, stack=None, cause=None):
|
|
||||||
Exception.__init__(self)
|
|
||||||
self.msg = msg
|
|
||||||
self.stack = stack
|
|
||||||
self.cause = cause
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
msg = self.msg.split(u'\n')
|
|
||||||
msg = u' | ' + u'\n | '.join(msg)
|
|
||||||
|
|
||||||
try:
|
|
||||||
stack = u'\n'.join(self.stack)
|
|
||||||
except TypeError:
|
|
||||||
stack = repr(self.stack)
|
|
||||||
stack = stack.split(u'\n')
|
|
||||||
stack = u' ' + u'\n '.join(stack)
|
|
||||||
|
|
||||||
return u'\n\n Message:\n{}\n\n Stack:\n\n{}'.format(msg, stack)
|
|
@ -41,6 +41,7 @@ from qgis.core import (QgsMessageLog,
|
|||||||
QgsMapLayer,
|
QgsMapLayer,
|
||||||
QgsProcessingProvider,
|
QgsProcessingProvider,
|
||||||
QgsProcessingAlgorithm,
|
QgsProcessingAlgorithm,
|
||||||
|
QgsProcessingException,
|
||||||
QgsProcessingParameterDefinition,
|
QgsProcessingParameterDefinition,
|
||||||
QgsProcessingOutputVectorLayer,
|
QgsProcessingOutputVectorLayer,
|
||||||
QgsProcessingOutputRasterLayer)
|
QgsProcessingOutputRasterLayer)
|
||||||
@ -54,7 +55,6 @@ from processing.gui.RenderingStyles import RenderingStyles
|
|||||||
from processing.gui.Postprocessing import handleAlgorithmResults
|
from processing.gui.Postprocessing import handleAlgorithmResults
|
||||||
from processing.gui.AlgorithmExecutor import execute
|
from processing.gui.AlgorithmExecutor import execute
|
||||||
from processing.tools import dataobjects
|
from processing.tools import dataobjects
|
||||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
|
||||||
|
|
||||||
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider # NOQA
|
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider # NOQA
|
||||||
#from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider # NOQA
|
#from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider # NOQA
|
||||||
@ -140,7 +140,7 @@ class Processing(object):
|
|||||||
print('Error: Algorithm not found\n')
|
print('Error: Algorithm not found\n')
|
||||||
msg = Processing.tr('Error: Algorithm {0} not found\n').format(algOrName)
|
msg = Processing.tr('Error: Algorithm {0} not found\n').format(algOrName)
|
||||||
feedback.reportError(msg)
|
feedback.reportError(msg)
|
||||||
raise GeoAlgorithmExecutionException(msg)
|
raise QgsProcessingException(msg)
|
||||||
|
|
||||||
# check for any mandatory parameters which were not specified
|
# check for any mandatory parameters which were not specified
|
||||||
for param in alg.parameterDefinitions():
|
for param in alg.parameterDefinitions():
|
||||||
@ -150,7 +150,7 @@ class Processing(object):
|
|||||||
msg = Processing.tr('Error: Missing parameter value for parameter {0}.').format(param.name())
|
msg = Processing.tr('Error: Missing parameter value for parameter {0}.').format(param.name())
|
||||||
print('Error: Missing parameter value for parameter %s.' % param.name())
|
print('Error: Missing parameter value for parameter %s.' % param.name())
|
||||||
feedback.reportError(msg)
|
feedback.reportError(msg)
|
||||||
raise GeoAlgorithmExecutionException(msg)
|
raise QgsProcessingException(msg)
|
||||||
|
|
||||||
if context is None:
|
if context is None:
|
||||||
context = dataobjects.createContext(feedback)
|
context = dataobjects.createContext(feedback)
|
||||||
@ -161,7 +161,7 @@ class Processing(object):
|
|||||||
print('Unable to execute algorithm\n' + str(msg))
|
print('Unable to execute algorithm\n' + str(msg))
|
||||||
msg = Processing.tr('Unable to execute algorithm\n{0}').format(msg)
|
msg = Processing.tr('Unable to execute algorithm\n{0}').format(msg)
|
||||||
feedback.reportError(msg)
|
feedback.reportError(msg)
|
||||||
raise GeoAlgorithmExecutionException(msg)
|
raise QgsProcessingException(msg)
|
||||||
|
|
||||||
if not alg.validateInputCrs(parameters, context):
|
if not alg.validateInputCrs(parameters, context):
|
||||||
print('Warning: Not all input layers use the same CRS.\n' +
|
print('Warning: Not all input layers use the same CRS.\n' +
|
||||||
@ -188,7 +188,7 @@ class Processing(object):
|
|||||||
else:
|
else:
|
||||||
msg = Processing.tr("There were errors executing the algorithm.")
|
msg = Processing.tr("There were errors executing the algorithm.")
|
||||||
feedback.reportError(msg)
|
feedback.reportError(msg)
|
||||||
raise GeoAlgorithmExecutionException(msg)
|
raise QgsProcessingException(msg)
|
||||||
|
|
||||||
if isinstance(feedback, MessageBarProgress):
|
if isinstance(feedback, MessageBarProgress):
|
||||||
feedback.close()
|
feedback.close()
|
||||||
|
@ -37,9 +37,9 @@ from qgis.core import (QgsFeature,
|
|||||||
QgsProcessingUtils,
|
QgsProcessingUtils,
|
||||||
QgsMessageLog,
|
QgsMessageLog,
|
||||||
QgsProperty,
|
QgsProperty,
|
||||||
|
QgsProcessingException,
|
||||||
QgsProcessingParameters,
|
QgsProcessingParameters,
|
||||||
QgsProcessingOutputLayerDefinition)
|
QgsProcessingOutputLayerDefinition)
|
||||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
|
||||||
from processing.gui.Postprocessing import handleAlgorithmResults
|
from processing.gui.Postprocessing import handleAlgorithmResults
|
||||||
from processing.tools import dataobjects
|
from processing.tools import dataobjects
|
||||||
from processing.tools.system import getTempFilename
|
from processing.tools.system import getTempFilename
|
||||||
@ -61,7 +61,7 @@ def execute(alg, parameters, context=None, feedback=None):
|
|||||||
try:
|
try:
|
||||||
results, ok = alg.run(parameters, context, feedback)
|
results, ok = alg.run(parameters, context, feedback)
|
||||||
return ok, results
|
return ok, results
|
||||||
except GeoAlgorithmExecutionException as e:
|
except QgsProcessingException as e:
|
||||||
QgsMessageLog.logMessage(str(sys.exc_info()[0]), 'Processing', QgsMessageLog.CRITICAL)
|
QgsMessageLog.logMessage(str(sys.exc_info()[0]), 'Processing', QgsMessageLog.CRITICAL)
|
||||||
if feedback is not None:
|
if feedback is not None:
|
||||||
feedback.reportError(e.msg)
|
feedback.reportError(e.msg)
|
||||||
|
@ -51,10 +51,10 @@ from processing.script.ScriptAlgorithm import ScriptAlgorithm # NOQA
|
|||||||
from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider # NOQA
|
from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider # NOQA
|
||||||
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider # NOQA
|
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider # NOQA
|
||||||
#from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider # NOQA
|
#from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider # NOQA
|
||||||
from processing.algs.gdal.GdalAlgorithmProvider import GdalAlgorithmProvider # NOQA
|
#from processing.algs.gdal.GdalAlgorithmProvider import GdalAlgorithmProvider # NOQA
|
||||||
from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider # NOQA
|
#from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider # NOQA
|
||||||
from processing.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider # NOQA
|
from processing.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider # NOQA
|
||||||
from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider # NOQA
|
#from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider # NOQA
|
||||||
|
|
||||||
|
|
||||||
from qgis.core import (QgsVectorLayer,
|
from qgis.core import (QgsVectorLayer,
|
||||||
|
@ -31,9 +31,9 @@ import nose2
|
|||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from qgis.core import (QgsProcessingAlgorithm,
|
from qgis.core import (QgsProcessingAlgorithm,
|
||||||
QgsProcessingFeedback)
|
QgsProcessingFeedback,
|
||||||
|
QgsProcessingException)
|
||||||
from qgis.testing import start_app, unittest
|
from qgis.testing import start_app, unittest
|
||||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
|
||||||
from processing.tools.dataobjects import createContext
|
from processing.tools.dataobjects import createContext
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ class TestAlg(QgsProcessingAlgorithm):
|
|||||||
return TestAlg()
|
return TestAlg()
|
||||||
|
|
||||||
def processAlgorithm(self, parameters, context, feedback):
|
def processAlgorithm(self, parameters, context, feedback):
|
||||||
raise GeoAlgorithmExecutionException('Exception while processing')
|
raise QgsProcessingException('Exception while processing')
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +52,6 @@ from processing.core.ProcessingConfig import ProcessingConfig
|
|||||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||||
from processing.tools.system import (getTempFilename,
|
from processing.tools.system import (getTempFilename,
|
||||||
removeInvalidChars)
|
removeInvalidChars)
|
||||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
|
||||||
|
|
||||||
ALL_TYPES = [-1]
|
ALL_TYPES = [-1]
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ import struct
|
|||||||
import numpy
|
import numpy
|
||||||
from osgeo import gdal
|
from osgeo import gdal
|
||||||
|
|
||||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
from qgis.core import QgsProcessingException
|
||||||
|
|
||||||
|
|
||||||
RASTER_EXTENSION_MAP = None
|
RASTER_EXTENSION_MAP = None
|
||||||
@ -96,7 +96,7 @@ def scanraster(layer, feedback):
|
|||||||
elif bandtype == 'Float64':
|
elif bandtype == 'Float64':
|
||||||
values = struct.unpack('d' * band.XSize, scanline)
|
values = struct.unpack('d' * band.XSize, scanline)
|
||||||
else:
|
else:
|
||||||
raise GeoAlgorithmExecutionException('Raster format not supported')
|
raise QgsProcessingException('Raster format not supported')
|
||||||
for value in values:
|
for value in values:
|
||||||
if value == nodata:
|
if value == nodata:
|
||||||
value = None
|
value = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user