From b207f1a6352b3d9f4e8742091c4d29a16590606f Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 21 Mar 2022 18:29:55 +0100 Subject: [PATCH] Adding lib/pp_admintools/config.py --- lib/pp_admintools/config.py | 100 ++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 lib/pp_admintools/config.py diff --git a/lib/pp_admintools/config.py b/lib/pp_admintools/config.py new file mode 100644 index 0000000..b0ad0f9 --- /dev/null +++ b/lib/pp_admintools/config.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +@author: Frank Brehm +@contact: frank.brehm@pixelpark.com +@copyright: © 2022 by Frank Brehm, Berlin +@summary: A module for providing a configuration for different things in this module. +""" +from __future__ import absolute_import + +# Standard module +import logging +import pwd +import socket + +# Third party modules + +from fb_tools.multi_config import MultiConfigError, BaseMultiConfig +from fb_tools.multi_config import DEFAULT_ENCODING + +# Own modules + +from .errors import PpError + +from .mailaddress import MailAddress + +from .xlate import XLATOR + +CONFIG_DIR = 'pixelpark' +__version__ = '0.1.0' +LOG = logging.getLogger(__name__) +VALID_MAIL_METHODS = ('smtp', 'sendmail') + +_ = XLATOR.gettext + + +# ============================================================================= +class PpConfigurationError(PpError, MultiConfigError): + """Base error class for all exceptions happened during + evaluation of configuration.""" + + pass + + +# ============================================================================= +class PpBaseConfiguration(BaseMultiConfig): + """Base class for reading and providing configuration.""" + + default_mail_recipients = [ + 'frank.brehm@pixelpark.com' + ] + default_mail_cc = [ + 'thomas.dalichow@pixelpark.com', + 'reinhard.schmitz@pixelpark.com', + ] + + default_reply_to = 'solution@pixelpark.com' + + default_mail_server = 'mx.pixelpark.com' + + current_user_name = pwd.getpwuid(os.getuid()).pw_name + current_user_gecos = pwd.getpwuid(os.getuid()).pw_gecos + default_mail_from = MailAddress(current_user_name, socket.getfqdn()) + + # ------------------------------------------------------------------------- + def __init__( + self, appname=None, verbose=0, version=__version__, base_dir=None, + append_appname_to_stems=True, config_dir=CONFIG_DIR, additional_stems=None, + additional_cfgdirs=None, encoding=DEFAULT_ENCODING, additional_config_file=None, + use_chardet=True, raise_on_error=True, initialized=False): + + self.mail_recipients = copy.copy(self.default_mail_recipients) + self.mail_from = '{n} <{m}>'.format( + n=self.current_user_gecos, m=self.default_mail_from) + self.mail_cc = copy.copy(self.default_mail_cc) + self.reply_to = self.default_reply_to + self.mail_method = 'smtp' + self.mail_server = self.default_mail_server + self.smtp_port = 25 + self._config_has_errors = None + + super(PpBaseConfiguration, self).__init__( + appname=appname, verbose=verbose, version=version, base_dir=base_dir, + append_appname_to_stems=append_appname_to_stems, config_dir=config_dir, + additional_stems=additional_stems, additional_cfgdirs=additional_cfgdirs, + encoding=encoding, additional_config_file=additional_config_file, + use_chardet=use_chardet, raise_on_error=raise_on_error, initialized=False) + + if initialized: + self.initialized = True + +# ============================================================================= + +if __name__ == "__main__": + + pass + +# ============================================================================= + +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list -- 2.39.5