From e6964560a85da4e95372af8980182f8511ff6710 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 20 Jan 2021 00:11:52 +0100 Subject: [PATCH] Some changes for fb_tools --- lib/pp_lib/cfg_app.py | 13 ++- lib/pp_lib/errors.py | 177 ++------------------------------------ lib/pp_lib/ldap_app.py | 6 +- lib/pp_lib/mailaddress.py | 12 +-- lib/pp_lib/mk_home_app.py | 10 +-- 5 files changed, 27 insertions(+), 191 deletions(-) diff --git a/lib/pp_lib/cfg_app.py b/lib/pp_lib/cfg_app.py index 6efbe10..f503805 100644 --- a/lib/pp_lib/cfg_app.py +++ b/lib/pp_lib/cfg_app.py @@ -3,7 +3,7 @@ """ @author: Frank Brehm @contact: frank.brehm@pixelpark.com -@copyright: © 2018 by Frank Brehm, Berlin +@copyright: © 2021 by Frank Brehm, Berlin @summary: The module for the application object with support for configuration files. """ @@ -38,19 +38,18 @@ from six.moves import configparser from configparser import Error as ConfigParseError # Own modules +from fb_tools.app import BaseApplication +from fb_tools.common import pp, to_bool, RE_DOT_AT_END + from .global_version import __version__ as __global_version__ from .errors import PpAppError -from .common import pp, to_bool, RE_DOT_AT_END - from .merge import merge_structure from .mailaddress import MailAddress -from .app import PpApplication - -__version__ = '0.7.1' +__version__ = '0.8.0' LOG = logging.getLogger(__name__) VALID_MAIL_METHODS = ('smtp', 'sendmail') @@ -65,7 +64,7 @@ class PpCfgAppError(PpAppError): # ============================================================================= -class PpConfigApplication(PpApplication): +class PpConfigApplication(BaseApplication): """ Class for configured application objects. """ diff --git a/lib/pp_lib/errors.py b/lib/pp_lib/errors.py index 2a566e7..5395a6b 100644 --- a/lib/pp_lib/errors.py +++ b/lib/pp_lib/errors.py @@ -8,11 +8,14 @@ # Standard modules import errno +# own modules +from fb_tools.errors import FbError, FbAppError -__version__ = '0.4.1' + +__version__ = '0.5.0' # ============================================================================= -class PpError(Exception): +class PpError(FbError): """ Base error class for all other self defined exceptions. """ @@ -21,179 +24,11 @@ class PpError(Exception): # ============================================================================= -class PpAppError(PpError): +class PpAppError(FbAppError): 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) - - # ============================================================================= if __name__ == "__main__": diff --git a/lib/pp_lib/ldap_app.py b/lib/pp_lib/ldap_app.py index 5b84e3a..ca4709d 100644 --- a/lib/pp_lib/ldap_app.py +++ b/lib/pp_lib/ldap_app.py @@ -3,7 +3,7 @@ """ @author: Frank Brehm @contact: frank.brehm@pixelpark.com -@copyright: © 2018 by Frank Brehm, Berlin +@copyright: © 2021 by Frank Brehm, Berlin @summary: The module for a LDAP based application object. """ from __future__ import absolute_import @@ -27,11 +27,11 @@ from ldap3.core.exceptions import LDAPPasswordIsMandatoryError from ldap3.utils.log import set_library_log_detail_level, ERROR, BASIC, PROTOCOL, NETWORK, EXTENDED # Own modules -from .common import pp, to_bool +from fb_tools.common import pp, to_bool from .cfg_app import PpCfgAppError, PpConfigApplication -__version__ = '0.4.9' +__version__ = '0.5.0' LOG = logging.getLogger(__name__) diff --git a/lib/pp_lib/mailaddress.py b/lib/pp_lib/mailaddress.py index 11c7f8f..b169d3a 100644 --- a/lib/pp_lib/mailaddress.py +++ b/lib/pp_lib/mailaddress.py @@ -3,7 +3,7 @@ """ @author: Frank Brehm @contact: frank.brehm@pixelpark.com -@copyright: © 2018 by Frank Brehm, Publicis Pixelpark GmbH, Berlin +@copyright: © 2021 by Frank Brehm, Publicis Pixelpark GmbH, Berlin @summary: The module for the MailAddress object. """ from __future__ import absolute_import @@ -13,16 +13,18 @@ import logging import re # Own modules -from .errors import InvalidMailAddressError +from fb_tools.errors import InvalidMailAddressError -from .common import to_str +from fb_tools.common import to_str -__version__ = '0.3.2' +from fb_tools.obj import FbGenericBaseObject + +__version__ = '0.4.0' log = logging.getLogger(__name__) # ============================================================================= -class MailAddress(object): +class MailAddress(FbGenericBaseObject): """ Class for encapsulating a mail simple address. """ diff --git a/lib/pp_lib/mk_home_app.py b/lib/pp_lib/mk_home_app.py index ce8b05c..4dbadbc 100644 --- a/lib/pp_lib/mk_home_app.py +++ b/lib/pp_lib/mk_home_app.py @@ -3,7 +3,7 @@ """ @author: Frank Brehm @contact: frank.brehm@pixelpark.com -@copyright: © 2018 by Frank Brehm, Berlin +@copyright: © 2021 by Frank Brehm, Berlin @summary: The module for the mk-home application object. """ from __future__ import absolute_import @@ -23,11 +23,11 @@ from ldap3 import ObjectDef # from ldap3.core.exceptions import LDAPKeyError # Own modules -from .common import pp +from fb_tools.common import pp from .ldap_app import PpLdapAppError, PpLdapApplication -__version__ = '0.5.1' +__version__ = '0.6.0' LOG = logging.getLogger(__name__) @@ -53,7 +53,7 @@ class PpMkHomeApp(PpLdapApplication): default_dn_counter = 'uid=uidNumber,ou=ldapTool,ou=Applications,o=Pixelpark,o=isp' # ------------------------------------------------------------------------- - def __init__(self, appname=None, version=__version__): + def __init__(self, appname=None, base_dir=None, version=__version__): self.initial_uid = self.default_initial_uid self.chroot_homedir = self.default_chroot_homedir @@ -76,7 +76,7 @@ class PpMkHomeApp(PpLdapApplication): super(PpMkHomeApp, self).__init__( appname=appname, version=version, description=description, - cfg_stems='mk-home' + base_dir=base_dir, cfg_stems='mk-home' ) self.initialized = True -- 2.39.5