mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[processing] remove GeoAlgorithmExecutionException
This commit is contained in:
parent
97a5a3dcbd
commit
56208540f9
@ -40,12 +40,12 @@ from qgis.core import (QgsProcessingFeedback,
|
||||
QgsProcessingAlgorithm,
|
||||
QgsProject,
|
||||
QgsProcessingUtils,
|
||||
QgsProcessingException,
|
||||
QgsProcessingParameterDefinition,
|
||||
QgsMessageLog)
|
||||
from qgis.gui import QgsHelp
|
||||
|
||||
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.outputs import OutputVector, OutputRaster, OutputTable, OutputHTML, Output
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
@ -76,7 +76,7 @@ class GeoAlgorithm(QgsProcessingAlgorithm):
|
||||
"""Here goes the algorithm itself.
|
||||
|
||||
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.
|
||||
:param parameters:
|
||||
:param context:
|
||||
@ -105,7 +105,7 @@ class GeoAlgorithm(QgsProcessingAlgorithm):
|
||||
it should be called using this method, since it performs
|
||||
some additional operations.
|
||||
|
||||
Raises a GeoAlgorithmExecutionException in case anything goes
|
||||
Raises a QgsProcessingException in case anything goes
|
||||
wrong.
|
||||
:param parameters:
|
||||
"""
|
||||
@ -124,18 +124,18 @@ class GeoAlgorithm(QgsProcessingAlgorithm):
|
||||
feedback.setProgress(100)
|
||||
self.convertUnsupportedFormats(context, feedback)
|
||||
self.runPostExecutionScript(feedback)
|
||||
except GeoAlgorithmExecutionException as gaee:
|
||||
except QgsProcessingException as gaee:
|
||||
lines = [self.tr('Error while executing algorithm')]
|
||||
lines.append(traceback.format_exc())
|
||||
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:
|
||||
# If something goes wrong and is not caught in the
|
||||
# algorithm, we catch it here and wrap it
|
||||
lines = [self.tr('Uncaught error while executing algorithm')]
|
||||
lines.append(traceback.format_exc())
|
||||
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):
|
||||
scriptFile = ProcessingConfig.getSetting(
|
||||
@ -235,7 +235,7 @@ class GeoAlgorithm(QgsProcessingAlgorithm):
|
||||
for out in self.outputs:
|
||||
out.resolveValue(self)
|
||||
except ValueError as e:
|
||||
raise GeoAlgorithmExecutionException(str(e))
|
||||
raise QgsProcessingException(str(e))
|
||||
|
||||
def setOutputCRS(self):
|
||||
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
|
||||
some additional operations.
|
||||
|
||||
Raises a GeoAlgorithmExecutionException in case anything goes
|
||||
Raises a QgsProcessingException in case anything goes
|
||||
wrong.
|
||||
: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,
|
||||
QgsProcessingProvider,
|
||||
QgsProcessingAlgorithm,
|
||||
QgsProcessingException,
|
||||
QgsProcessingParameterDefinition,
|
||||
QgsProcessingOutputVectorLayer,
|
||||
QgsProcessingOutputRasterLayer)
|
||||
@ -54,7 +55,6 @@ from processing.gui.RenderingStyles import RenderingStyles
|
||||
from processing.gui.Postprocessing import handleAlgorithmResults
|
||||
from processing.gui.AlgorithmExecutor import execute
|
||||
from processing.tools import dataobjects
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
|
||||
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider # NOQA
|
||||
#from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider # NOQA
|
||||
@ -140,7 +140,7 @@ class Processing(object):
|
||||
print('Error: Algorithm not found\n')
|
||||
msg = Processing.tr('Error: Algorithm {0} not found\n').format(algOrName)
|
||||
feedback.reportError(msg)
|
||||
raise GeoAlgorithmExecutionException(msg)
|
||||
raise QgsProcessingException(msg)
|
||||
|
||||
# check for any mandatory parameters which were not specified
|
||||
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())
|
||||
print('Error: Missing parameter value for parameter %s.' % param.name())
|
||||
feedback.reportError(msg)
|
||||
raise GeoAlgorithmExecutionException(msg)
|
||||
raise QgsProcessingException(msg)
|
||||
|
||||
if context is None:
|
||||
context = dataobjects.createContext(feedback)
|
||||
@ -161,7 +161,7 @@ class Processing(object):
|
||||
print('Unable to execute algorithm\n' + str(msg))
|
||||
msg = Processing.tr('Unable to execute algorithm\n{0}').format(msg)
|
||||
feedback.reportError(msg)
|
||||
raise GeoAlgorithmExecutionException(msg)
|
||||
raise QgsProcessingException(msg)
|
||||
|
||||
if not alg.validateInputCrs(parameters, context):
|
||||
print('Warning: Not all input layers use the same CRS.\n' +
|
||||
@ -188,7 +188,7 @@ class Processing(object):
|
||||
else:
|
||||
msg = Processing.tr("There were errors executing the algorithm.")
|
||||
feedback.reportError(msg)
|
||||
raise GeoAlgorithmExecutionException(msg)
|
||||
raise QgsProcessingException(msg)
|
||||
|
||||
if isinstance(feedback, MessageBarProgress):
|
||||
feedback.close()
|
||||
|
@ -37,9 +37,9 @@ from qgis.core import (QgsFeature,
|
||||
QgsProcessingUtils,
|
||||
QgsMessageLog,
|
||||
QgsProperty,
|
||||
QgsProcessingException,
|
||||
QgsProcessingParameters,
|
||||
QgsProcessingOutputLayerDefinition)
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.gui.Postprocessing import handleAlgorithmResults
|
||||
from processing.tools import dataobjects
|
||||
from processing.tools.system import getTempFilename
|
||||
@ -61,7 +61,7 @@ def execute(alg, parameters, context=None, feedback=None):
|
||||
try:
|
||||
results, ok = alg.run(parameters, context, feedback)
|
||||
return ok, results
|
||||
except GeoAlgorithmExecutionException as e:
|
||||
except QgsProcessingException as e:
|
||||
QgsMessageLog.logMessage(str(sys.exc_info()[0]), 'Processing', QgsMessageLog.CRITICAL)
|
||||
if feedback is not None:
|
||||
feedback.reportError(e.msg)
|
||||
|
@ -51,10 +51,10 @@ from processing.script.ScriptAlgorithm import ScriptAlgorithm # NOQA
|
||||
from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider # NOQA
|
||||
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider # NOQA
|
||||
#from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider # NOQA
|
||||
from processing.algs.gdal.GdalAlgorithmProvider import GdalAlgorithmProvider # NOQA
|
||||
from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider # NOQA
|
||||
#from processing.algs.gdal.GdalAlgorithmProvider import GdalAlgorithmProvider # NOQA
|
||||
#from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider # 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,
|
||||
|
@ -31,9 +31,9 @@ import nose2
|
||||
import shutil
|
||||
|
||||
from qgis.core import (QgsProcessingAlgorithm,
|
||||
QgsProcessingFeedback)
|
||||
QgsProcessingFeedback,
|
||||
QgsProcessingException)
|
||||
from qgis.testing import start_app, unittest
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.tools.dataobjects import createContext
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ class TestAlg(QgsProcessingAlgorithm):
|
||||
return TestAlg()
|
||||
|
||||
def processAlgorithm(self, parameters, context, feedback):
|
||||
raise GeoAlgorithmExecutionException('Exception while processing')
|
||||
raise QgsProcessingException('Exception while processing')
|
||||
return {}
|
||||
|
||||
|
||||
|
@ -52,7 +52,6 @@ from processing.core.ProcessingConfig import ProcessingConfig
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
from processing.tools.system import (getTempFilename,
|
||||
removeInvalidChars)
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
|
||||
ALL_TYPES = [-1]
|
||||
|
||||
|
@ -35,7 +35,7 @@ import struct
|
||||
import numpy
|
||||
from osgeo import gdal
|
||||
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from qgis.core import QgsProcessingException
|
||||
|
||||
|
||||
RASTER_EXTENSION_MAP = None
|
||||
@ -96,7 +96,7 @@ def scanraster(layer, feedback):
|
||||
elif bandtype == 'Float64':
|
||||
values = struct.unpack('d' * band.XSize, scanline)
|
||||
else:
|
||||
raise GeoAlgorithmExecutionException('Raster format not supported')
|
||||
raise QgsProcessingException('Raster format not supported')
|
||||
for value in values:
|
||||
if value == nodata:
|
||||
value = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user