Source code for rios.rioserrors

All exceptions used within rios. 

# This file is part of RIOS - Raster I/O Simplification
# Copyright (C) 2012  Sam Gillingham, Neil Flood
# 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 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <>.

import sys
import warnings
import inspect

[docs]class RiosError(Exception): """ Base class for RIOS exceptions """
[docs]class FileOpenError(RiosError): "Failed to open an input or output file"
[docs]class ImageOpenError(FileOpenError): "Image wasn't able to be opened by GDAL"
[docs]class ParameterError(RiosError): "Incorrect parameters passed to function"
[docs]class GDALLayerNumberError(RiosError): "A GDAL layer number was given, but was out of range"
[docs]class ResampleNeededError(RiosError): "Images do not match - resample needs to be turned on"
[docs]class OutsideImageBoundsError(RiosError): "Requested Block is not available"
[docs]class GdalWarpError(RiosError): "Error while running gdalwarp"
[docs]class ThematicError(RiosError): "File unable to be set to thematic"
[docs]class ProcessCancelledError(RiosError): "Process was cancelled by user"
[docs]class KeysMismatch(RiosError): "Keys do not match expected"
[docs]class MismatchedListLengthsError(RiosError): "Two lists had different lengths, when they were supposed to be the same length"
[docs]class AttributeTableColumnError(RiosError): "Unable to find specified column"
[docs]class AttributeTableTypeError(RiosError): "Type does not match that expected"
[docs]class ArrayShapeError(RiosError): "Error in shape of an array"
[docs]class TypeConversionError(RiosError): "Unknown type conversion"
[docs]class VectorAttributeError(RiosError): "Unable to find specified index in vector file"
[docs]class VectorGeometryTypeError(RiosError): "Unexpected Geometry type"
[docs]class VectorProjectionError(RiosError): "Vector projection does not match raster projection"
[docs]class VectorRasterizationError(RiosError): "Rasterisation of Vector dataset failed"
[docs]class VectorLayerError(RiosError): "Unable to find the specified layer"
[docs]class WrongControlsObject(RiosError): "The wrong type of control object has been passed to apply"
[docs]class RatBlockLengthError(RiosError): "Error with RAT block length, in ratapplier"
[docs]class RatMismatchError(RiosError): "Inconsistent RATs on inputs to ratapplier"
[docs]class IntersectionError(RiosError): "Images don't have a common area"
[docs]class JobMgrError(RiosError): "Errors from Jobmanager class"
[docs]class ColorTableGenerationError(RiosError): "Error generating a color table"
[docs]class PermissionError(RiosError): "Error due to permissions on temp files"
[docs]class TimeoutError(RiosError): "Something timed out"
[docs]class UnavailableError(RiosError): "A dependency is unavailable"
[docs]class WorkerExceptionError(RiosError): "A worker thread or process has raised an exception"
deprecationAlreadyWarned = set()
[docs]def deprecationWarning(msg, stacklevel=2): """ Print a deprecation warning to stderr. Includes the filename and line number of the call to the function which called this. The stacklevel argument controls how many stack levels above this gives the line number. Implemented in mimcry of warnings.warn(), which seems very flaky. Sometimes it prints, and sometimes not, unless PYTHONWARNINGS is set (or -W is used). This function at least seems to work consistently. """ # Get stack information, so we can report the file and line number # where the deprecated function was used. I copied the bulk of this # section from warnings.warn(). skip_file_prefixes = () # Not skipping anything # Some time between Python 3.10 and Python 2.12, they changed the # signature of their warnings._next_external_frame function. So, we # need to work out which one we have. nextFrameArgs = inspect.getfullargspec(warnings._next_external_frame) nextFrame2args = (len(nextFrameArgs.args) == 2) try: frame = sys._getframe(1) # Look for one frame less since the above line starts us off. for x in range(stacklevel - 1): if nextFrame2args: frame = warnings._next_external_frame(frame, skip_file_prefixes) else: frame = warnings._next_external_frame(frame) if frame is None: raise ValueError except ValueError: filename = "sys" lineno = 1 else: filename = frame.f_code.co_filename lineno = frame.f_lineno key = (filename, lineno) if key not in deprecationAlreadyWarned: print("{} (line {}):\n WARNING: {}".format(filename, lineno, msg), file=sys.stderr) deprecationAlreadyWarned.add(key)