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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# 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 <http://www.gnu.org/licenses/>.

import sys
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"
[docs]class SinglePassActionsError(RiosError): "An error in processing single-pass actions"
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. """ frame = inspect.currentframe() for i in range(stacklevel): if frame is not None: frame = frame.f_back if frame is None: 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)