From: Frank Brehm Date: Fri, 22 Sep 2023 08:14:51 +0000 (+0200) Subject: Separating all exception classes in module cr_vmware_tpl.errors X-Git-Tag: 3.0.0^2~30 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=d2691c04555f1b6eacfebff9a3b384333ecd853d;p=pixelpark%2Fcreate-vmware-tpl.git Separating all exception classes in module cr_vmware_tpl.errors --- diff --git a/lib/cr_vmware_tpl/app.py b/lib/cr_vmware_tpl/app.py index 63dbd4e..50117c3 100644 --- a/lib/cr_vmware_tpl/app.py +++ b/lib/cr_vmware_tpl/app.py @@ -31,6 +31,8 @@ from fb_tools.errors import FbAppError, ExpectedHandlerError from .config import CrTplConfiguration +from .errors import CrTplAppError + from .handler import CrTplHandler from .xlate import __module_dir__ as __xlate_module_dir__ @@ -38,19 +40,13 @@ from .xlate import __base_dir__ as __xlate_base_dir__ from .xlate import __mo_file__ as __xlate_mo_file__ from .xlate import XLATOR, LOCALE_DIR, DOMAIN -__version__ = '1.5.2' +__version__ = '1.5.3' LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -class CrTplAppError(FbAppError): - """ Base exception class for all exceptions in this application.""" - pass - - # ============================================================================= class NrTemplatesOptionAction(argparse.Action): diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index 3736e1d..72d03c9 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -34,7 +34,6 @@ from six.moves import configparser # Own modules from fb_tools.common import pp, to_str, is_sequence, to_bool -from fb_tools.errors import HandlerError, ExpectedHandlerError from fb_tools.handling_obj import CompletedProcess from fb_tools.handler import BaseHandler from fb_tools.xlate import format_list @@ -43,9 +42,11 @@ from . import print_section_start, print_section_end from .config import CrTplConfiguration +from .errors import CobblerError, ExpectedCobblerError + from .xlate import XLATOR -__version__ = '0.10.0' +__version__ = '0.10.1' LOG = logging.getLogger(__name__) @@ -53,16 +54,6 @@ _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -class CobblerError(HandlerError): - """Exception class for unexpected exceptions.""" - pass - -# ============================================================================= -class ExpectedCobblerError(ExpectedHandlerError, CobblerError): - """Exception class for predictible exceptions.""" - pass - # ============================================================================= class Cobbler(BaseHandler): """ @@ -79,7 +70,7 @@ class Cobbler(BaseHandler): if not isinstance(cfg, CrTplConfiguration): msg = _("{w} is not an instance of {c}, but an instance of {i} instead.").format( w='Parameter cfg', c='CrTplConfiguration', i=cfg.__class__.__name__) - raise HandlerError(msg) + raise CobblerError(msg) self.host = CrTplConfiguration.default_cobbler_host self.cobbler_bin = CrTplConfiguration.default_cobbler_bin diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index 0d630a2..e799a57 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -23,7 +23,7 @@ from pathlib import Path from fb_tools.common import is_sequence, pp, to_bool from fb_tools.obj import FbGenericBaseObject, FbBaseObject from fb_tools.collections import CIStringSet -from fb_tools.multi_config import MultiConfigError, BaseMultiConfig +from fb_tools.multi_config import BaseMultiConfig from fb_tools.multi_config import DEFAULT_ENCODING from fb_tools.xlate import format_list @@ -31,9 +31,11 @@ from fb_vmware.config import VSPhereConfigInfo from . import DEFAULT_CONFIG_DIR, DEFAULT_DISTRO_ARCH, MAX_PORT_NUMBER +from .errors import CrTplConfigError + from .xlate import XLATOR -__version__ = '2.3.0' +__version__ = '2.3.1' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -50,14 +52,6 @@ DEFAULT_ADMIN_FILTER = ( ) -# ============================================================================= -class CrTplConfigError(MultiConfigError): - """Base error class for all exceptions happened during - execution this configured application""" - - pass - - # ============================================================================= class LdapConnectionInfo(FbBaseObject): """Encapsulating all necessary data to connect to a LDAP server.""" diff --git a/lib/cr_vmware_tpl/errors.py b/lib/cr_vmware_tpl/errors.py new file mode 100644 index 0000000..4b89fee --- /dev/null +++ b/lib/cr_vmware_tpl/errors.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +@summary: The module for special error classes in this package + +@author: Frank Brehm +@contact: frank@brehm-online.com +@copyright: © 2023 by Frank Brehm, Berlin +""" +from __future__ import absolute_import + +# Standard modules + +# Third party modules + +from fb_tools.errors import FbAppError +from fb_tools.errors import FbHandlerError +from fb_tools.errors import HandlerError, ExpectedHandlerError +from fb_tools.multi_config import MultiConfigError + +# Own modules +from .xlate import XLATOR + +__version__ = '0.1.0' + +_ = XLATOR.gettext + + +MSG_NO_CLUSTER = _( + "Could not find a datastore of {size:0.1f} GiB size in " + "datastore cluster {c_name!r}.") + + +# ============================================================================= +class CrTplAppError(FbAppError): + """ Base exception class for all exceptions in this application.""" + pass + + +# ============================================================================= +class CrTplConfigError(MultiConfigError): + """Base error class for all exceptions happened during + execution this configured application""" + + pass + + +# ============================================================================= +class CobblerError(HandlerError): + """Exception class for unexpected exceptions.""" + pass + + +# ============================================================================= +class ExpectedCobblerError(ExpectedHandlerError, CobblerError): + """Exception class for predictible exceptions.""" + pass + + +# ============================================================================= +class TempVmExistsError(ExpectedHandlerError): + """Special error class for the case, if the temporary VM is already existing.""" + + # ------------------------------------------------------------------------- + def __init__(self, vm_name): + + self.vm_name = vm_name + + # ------------------------------------------------------------------------- + def __str__(self): + + msg = _("The temporary VM {!r} is already existing, cannot continue.").format(self.vm_name) + return msg + + +# ============================================================================= +class NoDatastoreFoundError(ExpectedHandlerError): + """Special error class for the case, no appropriate datastore coud be found.""" + + # ------------------------------------------------------------------------- + def __init__(self, data_size_gb, ds_cluster_name=None): + + self.data_size_gb = data_size_gb + self.ds_cluster_name = ds_cluster_name + + # ------------------------------------------------------------------------- + def __str__(self): + + if self.ds_cluster_name: + msg = MSG_NO_CLUSTER.format(size=self.data_size_gb, c_name=self.ds_cluster_name) + else: + msg = _("Could not find a datastore of {:0.1f} GiB size.").format( + self.data_size_gb) + + return msg + + +# ============================================================================= + +if __name__ == "__main__": + + pass + +# ============================================================================= + +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index 7d78ef7..daf0157 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -52,9 +52,11 @@ from .config import CrTplConfiguration, DEFAULT_PORT_LDAP, DEFAULT_PORT_LDAPS from .cobbler import Cobbler +from .errors import MSG_NO_CLUSTER, TempVmExistsError, NoDatastoreFoundError + from .xlate import XLATOR -__version__ = '2.3.3' +__version__ = '2.3.4' LOG = logging.getLogger(__name__) TZ = pytz.timezone('Europe/Berlin') @@ -62,49 +64,6 @@ TZ = pytz.timezone('Europe/Berlin') _ = XLATOR.gettext ngettext = XLATOR.ngettext -MSG_NO_CLUSTER = _( - "Could not find a datastore of {size:0.1f} GiB size in " - "datastore cluster {c_name!r}.") - - -# ============================================================================= -class TempVmExistsError(ExpectedHandlerError): - """Special error class for the case, if the temporary VM is already existing.""" - - # ------------------------------------------------------------------------- - def __init__(self, vm_name): - - self.vm_name = vm_name - - # ------------------------------------------------------------------------- - def __str__(self): - - msg = _("The temporary VM {!r} is already existing, cannot continue.").format(self.vm_name) - return msg - - -# ============================================================================= -class NoDatastoreFoundError(ExpectedHandlerError): - """Special error class for the case, no appropriate datastore coud be found.""" - - # ------------------------------------------------------------------------- - def __init__(self, data_size_gb, ds_cluster_name=None): - - self.data_size_gb = data_size_gb - self.ds_cluster_name = ds_cluster_name - - # ------------------------------------------------------------------------- - def __str__(self): - - if self.ds_cluster_name: - msg = MSG_NO_CLUSTER.format(size=self.data_size_gb, c_name=self.ds_cluster_name) - else: - msg = _("Could not find a datastore of {:0.1f} GiB size.").format( - self.data_size_gb) - - return msg - - # ============================================================================= class CrTplHandler(BaseHandler): """