From: Frank Brehm Date: Thu, 6 Dec 2018 17:27:15 +0000 (+0100) Subject: Substituting lib/webhooks/errors.py by fb_tools.errors X-Git-Tag: 1.6.4^2~107 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=67bfadb072026127c2d4e6ae9a57f6b86c9a86e0;p=pixelpark%2Fpuppetmaster-webhooks.git Substituting lib/webhooks/errors.py by fb_tools.errors --- diff --git a/lib/webhooks/errors.py b/lib/webhooks/errors.py deleted file mode 100644 index b453a9b..0000000 --- a/lib/webhooks/errors.py +++ /dev/null @@ -1,246 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" -@author: Frank Brehm -@summary: module for some common used error classes -""" - -# Standard modules -import errno - - -__version__ = '1.0.0' - -# ============================================================================= -class PpError(Exception): - """ - Base error class for all other self defined exceptions. - """ - - pass - - -# ============================================================================= -class PpAppError(PpError): - - pass - - -# ============================================================================= -class InvalidMailAddressError(PpError): - """Class for a exception in case of a malformed mail address.""" - - # ------------------------------------------------------------------------- - def __init__(self, address, msg=None): - - self.address = address - self.msg = msg - - # ------------------------------------------------------------------------- - def __str__(self): - - msg = "Wrong mail address {a!r} ({c})".format( - a=self.address, c=self.address.__class__.__name__) - if self.msg: - msg += ': ' + self.msg - else: - msg += '.' - return msg - - -# ============================================================================= -class FunctionNotImplementedError(PpError, NotImplementedError): - """ - Error class for not implemented functions. - """ - - # ------------------------------------------------------------------------- - def __init__(self, function_name, class_name): - """ - Constructor. - - @param function_name: the name of the not implemented function - @type function_name: str - @param class_name: the name of the class of the function - @type class_name: str - - """ - - self.function_name = function_name - if not function_name: - self.function_name = '__unkown_function__' - - self.class_name = class_name - if not class_name: - self.class_name = '__unkown_class__' - - # ------------------------------------------------------------------------- - def __str__(self): - """ - Typecasting into a string for error output. - """ - - msg = "Function {func}() has to be overridden in class {cls!r}." - return msg.format(func=self.function_name, cls=self.class_name) - -# ============================================================================= -class IoTimeoutError(PpError, IOError): - """ - Special error class indicating a timout error on a read/write operation - """ - - # ------------------------------------------------------------------------- - def __init__(self, strerror, timeout, filename=None): - """ - Constructor. - - @param strerror: the error message about the operation - @type strerror: str - @param timeout: the timout in seconds leading to the error - @type timeout: float - @param filename: the filename leading to the error - @type filename: str - - """ - - t_o = None - try: - t_o = float(timeout) - except ValueError: - pass - self.timeout = t_o - - if t_o is not None: - strerror += " (timeout after {:0.1f} secs)".format(t_o) - - if filename is None: - super(IoTimeoutError, self).__init__(errno.ETIMEDOUT, strerror) - else: - super(IoTimeoutError, self).__init__( - errno.ETIMEDOUT, strerror, filename) - -# ============================================================================= -class ReadTimeoutError(IoTimeoutError): - """ - Special error class indicating a timout error on reading of a file. - """ - - # ------------------------------------------------------------------------- - def __init__(self, timeout, filename): - """ - Constructor. - - @param timeout: the timout in seconds leading to the error - @type timeout: float - @param filename: the filename leading to the error - @type filename: str - - """ - - strerror = "Timeout error on reading" - super(ReadTimeoutError, self).__init__(strerror, timeout, filename) - - -# ============================================================================= -class WriteTimeoutError(IoTimeoutError): - """ - Special error class indicating a timout error on a writing into a file. - """ - - # ------------------------------------------------------------------------- - def __init__(self, timeout, filename): - """ - Constructor. - - @param timeout: the timout in seconds leading to the error - @type timeout: float - @param filename: the filename leading to the error - @type filename: str - - """ - - strerror = "Timeout error on writing" - super(WriteTimeoutError, self).__init__(strerror, timeout, filename) - -# ============================================================================= -class CouldntOccupyLockfileError(PpError): - """ - Special error class indicating, that a lockfile couldn't coccupied - after a defined time. - """ - - # ----------------------------------------------------- - def __init__(self, lockfile, duration, tries): - """ - Constructor. - - @param lockfile: the lockfile, which could't be occupied. - @type lockfile: str - @param duration: The duration in seconds, which has lead to this situation - @type duration: float - @param tries: the number of tries creating the lockfile - @type tries: int - - """ - - self.lockfile = str(lockfile) - self.duration = float(duration) - self.tries = int(tries) - - # ----------------------------------------------------- - def __str__(self): - - return "Couldn't occupy lockfile {!r} in {:0.1f} seconds with {} tries.".format( - self.lockfile, self.duration, self.tries) - - -# ============================================================================= -class CommandNotFoundError(PpError): - """ - Special exception, if one ore more OS commands were not found. - - """ - - # ------------------------------------------------------------------------- - def __init__(self, cmd_list): - """ - Constructor. - - @param cmd_list: all not found OS commands. - @type cmd_list: list - - """ - - self.cmd_list = None - if cmd_list is None: - self.cmd_list = ["Unknown OS command."] - elif isinstance(cmd_list, list): - self.cmd_list = cmd_list - else: - self.cmd_list = [cmd_list] - - if len(self.cmd_list) < 1: - raise ValueError("Empty command list given.") - - # ------------------------------------------------------------------------- - def __str__(self): - """ - Typecasting into a string for error output. - """ - - cmds = ', '.join([("'" + str(x) + "'") for x in self.cmd_list]) - msg = "Could not found OS command" - if len(self.cmd_list) != 1: - msg += 's' - msg += ": " + cmds - return msg - - -# ============================================================================= - -if __name__ == "__main__": - pass - -# ============================================================================= - -# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/lib/webhooks/handler.py b/lib/webhooks/handler.py index 69da623..cf5c201 100644 --- a/lib/webhooks/handler.py +++ b/lib/webhooks/handler.py @@ -26,9 +26,8 @@ import six # Own modules from fb_tools.common import caller_search_path - -from .errors import ReadTimeoutError, WriteTimeoutError -from .errors import CommandNotFoundError +from fb_tools.errors import ReadTimeoutError, WriteTimeoutError +from fb_tools.errors import CommandNotFoundError from .obj import BaseObjectError from .obj import BaseObject diff --git a/lib/webhooks/lock_handler.py b/lib/webhooks/lock_handler.py index 657c01d..ec38251 100644 --- a/lib/webhooks/lock_handler.py +++ b/lib/webhooks/lock_handler.py @@ -26,8 +26,7 @@ from six import reraise # Own modules from fb_tools.common import to_utf8 - -from .errors import CouldntOccupyLockfileError +from fb_tools.errors import CouldntOccupyLockfileError from .obj import BaseObject diff --git a/lib/webhooks/obj.py b/lib/webhooks/obj.py index 30edcc0..cc150a8 100644 --- a/lib/webhooks/obj.py +++ b/lib/webhooks/obj.py @@ -18,8 +18,7 @@ import traceback # Own modules from fb_tools.common import pp, to_bytes - -from .errors import PpError +from fb_tools.errors import FbError __version__ = '1.1.1' @@ -27,7 +26,7 @@ LOG = logging.getLogger(__name__) # ============================================================================= -class BaseObjectError(PpError): +class BaseObjectError(FbError): """ Base error class useable by all descendand objects. """ diff --git a/requirements.txt b/requirements.txt index 58902ea..91d77ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,4 @@ dnspython flake8 docker-py pathlib -git+https://git.pixelpark.com/frabrehm/python_fb_tools.git@1.2.4 +git+https://git.pixelpark.com/frabrehm/python_fb_tools.git@1.2.5