From: Frank Brehm Date: Fri, 9 Mar 2018 14:05:16 +0000 (+0100) Subject: Changed location of definition of CommandNotFoundError X-Git-Tag: 0.8.4^2~13 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=40544fc9e26e3ca32dba4603fee4caf982bd7136;p=pixelpark%2Fpuppetmaster-webhooks.git Changed location of definition of CommandNotFoundError --- diff --git a/lib/webhooks/errors.py b/lib/webhooks/errors.py index 684b467..5186877 100644 --- a/lib/webhooks/errors.py +++ b/lib/webhooks/errors.py @@ -9,7 +9,7 @@ import errno -__version__ = '0.1.1' +__version__ = '0.1.2' # ============================================================================= class PpError(Exception): @@ -194,6 +194,48 @@ class CouldntOccupyLockfileError(PpError): 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__": diff --git a/lib/webhooks/handler.py b/lib/webhooks/handler.py index e2fee78..8024a65 100644 --- a/lib/webhooks/handler.py +++ b/lib/webhooks/handler.py @@ -28,11 +28,12 @@ import six from .common import caller_search_path from .errors import ReadTimeoutError, WriteTimeoutError +from .errors import CommandNotFoundError from .obj import BaseObjectError from .obj import BaseObject -__version__ = '0.1.1' +__version__ = '0.1.2' log = logging.getLogger(__name__) @@ -51,48 +52,6 @@ class BaseHandlerError(BaseObjectError): pass -# ============================================================================= -class CommandNotFoundError(BaseHandlerError): - """ - 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 - - # ============================================================================= class BaseHandler(BaseObject): """