From: Frank Brehm Date: Fri, 7 Sep 2018 10:00:28 +0000 (+0200) Subject: Some changes because of Exceptions X-Git-Tag: 1.0.1~2^2~6 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=4ce53e1fb7b1dafa3f0551e81efb4ea51e412d2d;p=pixelpark%2Fpuppetmaster-webhooks.git Some changes because of Exceptions --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 4c06e28..ff926e6 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.12.1' +__version__ = '0.12.2' # vim: ts=4 et list diff --git a/lib/webhooks/base_app.py b/lib/webhooks/base_app.py index 04bea9e..3473336 100644 --- a/lib/webhooks/base_app.py +++ b/lib/webhooks/base_app.py @@ -21,6 +21,7 @@ import traceback import io import cgi import textwrap +import copy from email.message import EmailMessage @@ -59,6 +60,11 @@ class BaseHookError(BaseObjectError): pass +# ============================================================================= +class UncriticalHookError(BaseHookError): + """ + Class for uncritical errors, which could and should be caught. + """ # ============================================================================= class BaseHookApp(BaseObject): @@ -93,6 +99,8 @@ class BaseHookApp(BaseObject): 'errors': 'surrogateescape', } + main_branches = ('development', 'test', 'production') + # ------------------------------------------------------------------------- def __init__(self, appname=None, base_dir=None, verbose=0, version=__version__): """Constructor.""" @@ -308,6 +316,7 @@ class BaseHookApp(BaseObject): res['html_title'] = self.html_title res['no_error_mail'] = self.no_error_mail res['open_args'] = self.open_args + res['main_branches'] = copy.copy(self.main_branches) return res @@ -928,11 +937,11 @@ class BaseHookApp(BaseObject): LOG.debug("Searching for {!r} ...".format(self.cachefile)) if not os.path.exists(self.cachefile): - raise ShowModulesUncriticalError( + raise UncriticalHookError( "Cache file {!r} not found.".format(self.cachefile)) if not os.access(self.cachefile, os.R_OK): - raise ShowModulesUncriticalError( + raise UncriticalHookError( "Cache file {!r} not readable.".format(self.cachefile)) modules = ModuleInfoDict( @@ -962,7 +971,7 @@ class BaseHookApp(BaseObject): if self.should_display(module_info): modules.append(module_info) except yaml.YAMLError as e: - raise ShowModulesUncriticalError( + raise UncriticalHookError( "Could not evaluate content of {f!r}: {e}".format(f=self.cachefile, e=e)) if self.verbose > 3: LOG.debug("Content of {f!r}:\n{c}".format(f=self.cachefile, c=pp(modules.as_list()))) @@ -971,6 +980,10 @@ class BaseHookApp(BaseObject): return modules + # ------------------------------------------------------------------------- + def should_display(self, module_info): + + return True # ============================================================================= diff --git a/lib/webhooks/show_modules.py b/lib/webhooks/show_modules.py index ebbcc7c..2dd6a2f 100644 --- a/lib/webhooks/show_modules.py +++ b/lib/webhooks/show_modules.py @@ -27,7 +27,7 @@ from . import __version__ from .common import pp, is_sequence -from .base_app import BaseHookError, BaseHookApp +from .base_app import BaseHookError, BaseHookApp, UncriticalHookError from .module_info import ModuleInfo @@ -44,7 +44,7 @@ class ShowModulesError(BaseHookError): pass # ============================================================================= -class ShowModulesUncriticalError(ShowModulesError): +class ShowModulesUncriticalError(ShowModulesError, UncriticalHookError): pass @@ -54,8 +54,6 @@ class ShowModulesApp(BaseHookApp): Class for the application objects. """ - main_branches = ('development', 'test', 'production') - # ------------------------------------------------------------------------- def __init__(self, output_type='json', appname=None, verbose=0, version=__version__): """Constructor.""" @@ -83,8 +81,6 @@ class ShowModulesApp(BaseHookApp): res = super(ShowModulesApp, self).as_dict(short=short) - res['main_branches'] = copy.copy(self.main_branches) - return res # ------------------------------------------------------------------------- @@ -197,7 +193,7 @@ class ShowModulesApp(BaseHookApp): module_infos = [] try: module_infos = self.read_cache_file() - except ShowModulesUncriticalError as e: + except UncriticalHookError as e: LOG.error(str(e)) else: self.output_modules(module_infos)