Skip to content
Permalink
Browse files
[processing] Move some log handling to c++ class
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent 5169e0d commit 1394c28d1345e06b396e86977edf16ec1d26e8f4
Showing with 357 additions and 299 deletions.
  1. +1 −0 doc/api_break.dox
  2. +5 −0 python/core/processing/qgsprocessingutils.sip
  3. +4 −3 python/plugins/processing/algs/gdal/GdalUtils.py
  4. +5 −6 python/plugins/processing/algs/grass7/Grass7Algorithm.py
  5. +7 −6 python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py
  6. +5 −3 python/plugins/processing/algs/grass7/Grass7Utils.py
  7. +5 −4 python/plugins/processing/algs/qgis/Centroids.py
  8. +10 −6 python/plugins/processing/algs/qgis/Clip.py
  9. +8 −4 python/plugins/processing/algs/qgis/Difference.py
  10. +16 −14 python/plugins/processing/algs/qgis/Dissolve.py
  11. +7 −4 python/plugins/processing/algs/qgis/EliminateSelection.py
  12. +3 −3 python/plugins/processing/algs/qgis/FixGeometry.py
  13. +9 −9 python/plugins/processing/algs/qgis/Gridify.py
  14. +5 −4 python/plugins/processing/algs/qgis/Heatmap.py
  15. +12 −8 python/plugins/processing/algs/qgis/Intersection.py
  16. +6 −5 python/plugins/processing/algs/qgis/RandomPointsAlongLines.py
  17. +6 −5 python/plugins/processing/algs/qgis/RandomPointsExtent.py
  18. +6 −5 python/plugins/processing/algs/qgis/RandomPointsLayer.py
  19. +4 −4 python/plugins/processing/algs/qgis/RandomPointsPolygonsFixed.py
  20. +4 −4 python/plugins/processing/algs/qgis/RandomPointsPolygonsVariable.py
  21. +25 −25 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
  22. +11 −3 python/plugins/processing/algs/qgis/ShortestPathLayerToPoint.py
  23. +4 −3 python/plugins/processing/algs/qgis/ShortestPathPointToLayer.py
  24. +5 −4 python/plugins/processing/algs/qgis/SimplifyGeometries.py
  25. +3 −3 python/plugins/processing/algs/qgis/SplitLinesWithLines.py
  26. +3 −3 python/plugins/processing/algs/qgis/SplitWithLines.py
  27. +11 −6 python/plugins/processing/algs/qgis/SymmetricalDifference.py
  28. +22 −18 python/plugins/processing/algs/qgis/Union.py
  29. +4 −4 python/plugins/processing/algs/qgis/ui/FieldsCalculatorDialog.py
  30. +4 −3 python/plugins/processing/algs/r/RAlgorithm.py
  31. +6 −5 python/plugins/processing/algs/r/RAlgorithmProvider.py
  32. +4 −3 python/plugins/processing/algs/r/RUtils.py
  33. +3 −2 python/plugins/processing/algs/saga/SagaAlgorithm.py
  34. +11 −10 python/plugins/processing/algs/saga/SagaAlgorithmProvider.py
  35. +6 −5 python/plugins/processing/algs/saga/SagaUtils.py
  36. +6 −6 python/plugins/processing/core/GeoAlgorithm.py
  37. +6 −6 python/plugins/processing/core/Processing.py
  38. +21 −45 python/plugins/processing/core/ProcessingLog.py
  39. +1 −2 python/plugins/processing/gui/AlgorithmDialog.py
  40. +3 −3 python/plugins/processing/gui/AlgorithmExecutor.py
  41. +4 −3 python/plugins/processing/gui/HelpEditionDialog.py
  42. +9 −11 python/plugins/processing/gui/HistoryDialog.py
  43. +5 −4 python/plugins/processing/gui/Postprocessing.py
  44. +7 −6 python/plugins/processing/modeler/ModelerAlgorithmProvider.py
  45. +7 −6 python/plugins/processing/modeler/ModelerDialog.py
  46. +4 −3 python/plugins/processing/script/ScriptAlgorithm.py
  47. +5 −4 python/plugins/processing/script/ScriptUtils.py
  48. +17 −6 python/plugins/processing/tools/vector.py
  49. +6 −0 src/core/processing/qgsprocessingutils.cpp
  50. +6 −0 src/core/processing/qgsprocessingutils.h
@@ -2229,6 +2229,7 @@ object of type QgsProcessingFeedback, and will need to adapt their use of progre
- SilentProgress was removed. Use the base QgsProcessingFeedback class instead.
- algList was removed. Use QgsApplication.processingRegistry() instead.
- Processing.algs was removed. QgsApplication.processingRegistry().algorithms() instead.
- ProcessingLog should not be used when reporting log messages from algorithms. Use QgsProcessingUtils.logMessage() instead.

Triangulation {#qgis_api_break_3_0_Triangulation}
-------------
@@ -124,6 +124,11 @@ class QgsProcessingUtils
:rtype: list of QVariant
%End

static void logMessage( QgsMessageLog::MessageLevel level, const QString &message );
%Docstring
Logs a processing ``message`` of a specified ``level`` to the QGIS message log.
%End

};


@@ -37,9 +37,10 @@
from qgis.core import (QgsApplication,
QgsVectorFileWriter,
QgsProcessingFeedback,
QgsProcessingUtils,
QgsMessageLog,
QgsSettings)
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
from processing.tools.system import isWindows, isMac

try:
@@ -79,7 +80,7 @@ def runGdal(commands, feedback=None):
os.putenv('PATH', envval)

fused_command = ' '.join([str(c) for c in commands])
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, fused_command)
QgsProcessingUtils.logMessage(QgsMessageLog.INFO, fused_command)
feedback.pushInfo('GDAL command:')
feedback.pushCommandInfo(fused_command)
feedback.pushInfo('GDAL command output:')
@@ -107,7 +108,7 @@ def runGdal(commands, feedback=None):
else:
raise IOError(e.message + u'\nTried 5 times without success. Last iteration stopped after reading {} line(s).\nLast line(s):\n{}'.format(len(loglines), u'\n'.join(loglines[-10:])))

ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
QgsProcessingUtils.logMessage(QgsMessageLog.INFO, loglines)
GdalUtils.consoleOutput = loglines

@staticmethod
@@ -34,12 +34,13 @@
from qgis.PyQt.QtCore import QCoreApplication, QUrl

from qgis.core import (QgsRasterLayer,
QgsApplication)
QgsApplication,
QgsProcessingUtils,
QgsMessageLog)
from qgis.utils import iface

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

from processing.core.parameters import (getParameterFromString,
@@ -188,9 +189,7 @@ def defineCharacteristicsFromFile(self):
"txt"))
line = lines.readline().strip('\n').strip()
except Exception as e:
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(self.descriptionFile, line))
QgsProcessingUtils.logMessage(QgsMessageLog.CRITICAL, self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(self.descriptionFile, line))
raise e

self.addParameter(ParameterExtent(
@@ -300,7 +299,7 @@ def processAlgorithm(self, context, feedback):
feedback.pushCommandInfo(line)
loglines.append(line)
if ProcessingConfig.getSetting(Grass7Utils.GRASS_LOG_COMMANDS):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
QgsProcessingUtils.logMessage(QgsMessageLog.INFO, loglines)

Grass7Utils.executeGrass7(self.commands, feedback, self.outputCommands)

@@ -29,9 +29,10 @@
import os
from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (QgsApplication,
QgsProcessingProvider)
QgsProcessingProvider,
QgsMessageLog,
QgsProcessingUtils)
from processing.core.ProcessingConfig import ProcessingConfig, Setting
from processing.core.ProcessingLog import ProcessingLog
from .Grass7Utils import Grass7Utils
from .Grass7Algorithm import Grass7Algorithm
from processing.tools.system import isWindows, isMac
@@ -97,12 +98,12 @@ def createAlgsList(self):
if alg.name().strip() != '':
algs.append(alg)
else:
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
QgsProcessingUtils.logMessage(
QgsMessageLog.CRITICAL,
self.tr('Could not open GRASS GIS 7 algorithm: {0}').format(descriptionFile))
except Exception as e:
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
QgsProcessingUtils.logMessage(
QgsMessageLog.CRITICAL,
self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(descriptionFile, str(e)))
algs.append(nviz7())
return algs
@@ -31,10 +31,12 @@
import shutil
import subprocess
import os
from qgis.core import QgsApplication

from qgis.core import (QgsApplication,
QgsProcessingUtils,
QgsMessageLog)
from qgis.PyQt.QtCore import QCoreApplication
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
from processing.tools.system import userFolder, isWindows, isMac, tempFolder, mkdir
from processing.tests.TestData import points

@@ -333,7 +335,7 @@ def executeGrass7(commands, feedback, outputCommands=None):
feedback.pushConsoleInfo(line)

if ProcessingConfig.getSetting(Grass7Utils.GRASS_LOG_CONSOLE):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
QgsProcessingUtils.logMessage(QgsMessageLog.INFO, loglines)

# GRASS session is used to hold the layers already exported or
# produced in GRASS between multiple calls to GRASS algorithms.
@@ -29,10 +29,11 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsWkbTypes, QgsProcessingUtils
from qgis.core import (QgsWkbTypes,
QgsProcessingUtils,
QgsMessageLog)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector
@@ -80,8 +81,8 @@ def processAlgorithm(self, context, feedback):
if input_feature.geometry():
output_geometry = input_feature.geometry().centroid()
if not output_geometry:
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
'Error calculating centroid for feature {}'.format(input_feature.id()))
QgsProcessingUtils.logMessage(QgsMessageLog.WARNING,
'Error calculating centroid for feature {}'.format(input_feature.id()))
output_feature.setGeometry(output_geometry)

writer.addFeature(output_feature)
@@ -29,10 +29,14 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeature, QgsGeometry, QgsFeatureRequest, QgsWkbTypes, QgsProcessingUtils
from qgis.core import (QgsFeature,
QgsGeometry,
QgsFeatureRequest,
QgsWkbTypes,
QgsMessageLog,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector
@@ -137,10 +141,10 @@ def processAlgorithm(self, context, feedback):
out_feat.setAttributes(in_feat.attributes())
writer.addFeature(out_feat)
except:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('Feature geometry error: One or more '
'output features ignored due to '
'invalid geometry.'))
QgsProcessingUtils.logMessage(QgsMessageLog.CRITICAL,
self.tr('Feature geometry error: One or more '
'output features ignored due to '
'invalid geometry.'))
continue

if single_clip_feature:
@@ -29,8 +29,12 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWkbTypes, QgsProcessingUtils
from processing.core.ProcessingLog import ProcessingLog
from qgis.core import (QgsFeatureRequest,
QgsFeature,
QgsGeometry,
QgsWkbTypes,
QgsMessageLog,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
@@ -98,8 +102,8 @@ def processAlgorithm(self, context, feedback):
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
except:
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
self.tr('Feature geometry error: One or more output features ignored due to invalid geometry.'))
QgsProcessingUtils.logMessage(QgsMessageLog.WARNING,
self.tr('Feature geometry error: One or more output features ignored due to invalid geometry.'))
continue

feedback.setProgress(int(current * total))
@@ -30,9 +30,11 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeature, QgsGeometry, QgsProcessingUtils
from qgis.core import (QgsFeature,
QgsGeometry,
QgsMessageLog,
QgsProcessingUtils)

from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
@@ -106,12 +108,12 @@ def processAlgorithm(self, context, feedback):
errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('ValidateGeometry()'
'error: One or more '
'input features have '
'invalid geometry: ') +
error.what())
QgsProcessingUtils.logMessage(QgsMessageLog.CRITICAL,
self.tr('ValidateGeometry()'
'error: One or more '
'input features have '
'invalid geometry: ') +
error.what())
continue

geom_queue.append(tmpInGeom)
@@ -149,12 +151,12 @@ def processAlgorithm(self, context, feedback):
errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('ValidateGeometry() '
'error: One or more input'
'features have invalid '
'geometry: ') +
error.what())
QgsProcessingUtils.logMessage(QgsMessageLog.CRITICAL,
self.tr('ValidateGeometry() '
'error: One or more input'
'features have invalid '
'geometry: ') +
error.what())

if index_attrs not in attribute_dict:
# keep attributes of first feature
@@ -30,11 +30,14 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry
from qgis.core import (QgsFeatureRequest,
QgsFeature,
QgsGeometry,
QgsMessageLog,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterSelection
from processing.core.outputs import OutputVector
@@ -83,8 +86,8 @@ def processAlgorithm(self, context, feedback):
smallestArea = self.getParameterValue(self.MODE) == self.MODE_SMALLEST_AREA

if inLayer.selectedFeatureCount() == 0:
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
self.tr('{0}: (No selection in input layer "{1}")').format(self.displayName(), self.getParameterValue(self.INPUT)))
QgsProcessingUtils.logMessage(QgsMessageLog.WARNING,
self.tr('{0}: (No selection in input layer "{1}")').format(self.displayName(), self.getParameterValue(self.INPUT)))

featToEliminate = []
selFeatIds = inLayer.selectedFeatureIds()
@@ -28,13 +28,13 @@
from qgis.core import (QgsWkbTypes,
QgsGeometry,
QgsApplication,
QgsMessageLog,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.ProcessingLog import ProcessingLog
from processing.tools import dataobjects, vector


@@ -88,8 +88,8 @@ def processAlgorithm(self, context, feedback):
if inputFeature.geometry():
outputGeometry = inputFeature.geometry().makeValid()
if not outputGeometry:
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
'makeValid failed for feature {}'.format(inputFeature.id()))
QgsProcessingUtils.logMessage(QgsMessageLog.WARNING,
'makeValid failed for feature {}'.format(inputFeature.id()))

if outputGeometry.wkbType() == QgsWkbTypes.Unknown or QgsWkbTypes.flatType(outputGeometry.geometry().wkbType()) == QgsWkbTypes.GeometryCollection:
tmpGeometries = outputGeometry.asGeometryCollection()
@@ -30,10 +30,10 @@
QgsPoint,
QgsWkbTypes,
QgsApplication,
QgsMessageLog,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputVector
@@ -100,8 +100,8 @@ def processAlgorithm(self, context, feedback):
elif geomType == QgsWkbTypes.LineString:
points = self._gridify(geom.asPolyline(), hSpacing, vSpacing)
if len(points) < 2:
ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
newGeom = None
else:
newGeom = QgsGeometry.fromPolyline(points)
@@ -112,8 +112,8 @@ def processAlgorithm(self, context, feedback):
if len(points) > 1:
polyline.append(points)
if len(polyline) <= 0:
ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
newGeom = None
else:
newGeom = QgsGeometry.fromMultiPolyline(polyline)
@@ -125,8 +125,8 @@ def processAlgorithm(self, context, feedback):
if len(points) > 1:
polygon.append(points)
if len(polygon) <= 0:
ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
newGeom = None
else:
newGeom = QgsGeometry.fromPolygon(polygon)
@@ -143,8 +143,8 @@ def processAlgorithm(self, context, feedback):
multipolygon.append(newPolygon)

if len(multipolygon) <= 0:
ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
newGeom = None
else:
newGeom = QgsGeometry.fromMultiPolygon(multipolygon)
Loading

0 comments on commit 1394c28

Please sign in to comment.