]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Starting wit dpx-show-mail-ldap-config
authorFrank Brehm <frank@brehm-online.com>
Wed, 18 May 2022 14:19:52 +0000 (16:19 +0200)
committerFrank Brehm <frank@brehm-online.com>
Wed, 18 May 2022 14:19:52 +0000 (16:19 +0200)
lib/pp_admintools/show_ldap_mail_config.py [new file with mode: 0644]

diff --git a/lib/pp_admintools/show_ldap_mail_config.py b/lib/pp_admintools/show_ldap_mail_config.py
new file mode 100644 (file)
index 0000000..8fd5925
--- /dev/null
@@ -0,0 +1,118 @@
+#!/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 the application class for dpx-show-mail-ldap-config application.
+"""
+from __future__ import absolute_import
+
+import os
+import logging
+import textwrap
+import datetime
+
+# Third party modules
+from pytz import timezone, UnknownTimeZoneError
+
+from fb_tools.common import pp, to_str
+
+# Own modules
+from . import __version__ as GLOBAL_VERSION
+
+from .errors import PpAppError
+
+from .mail_config import MailConfigError, MailConfiguration
+
+from .ldap_config import LdapConfigError, LdapConfiguration
+
+from .mail_app import MailAppError, BaseMailApplication
+
+from .ldap_app import LdapAppError, BaseLdapApplication
+
+from .xlate import XLATOR
+
+__version__ = '0.1.0'
+LOG = logging.getLogger(__name__)
+
+_ = XLATOR.gettext
+
+
+# =============================================================================
+class ShowConfigError(PpAppError):
+    pass
+
+
+# =============================================================================
+class ShowMailLdapConfiguration(MailConfiguration, LdapConfiguration):
+    pass
+
+# =============================================================================
+class ShowMailLdapConfigApp(BaseMailApplication, BaseLdapApplication):
+    """
+    Application class for dpx-show-mail-ldap-config, which should show all relevant
+    configured options for Mail and LDAP supporting applications.
+    """
+
+    default_local_tz_name = 'Europe/Berlin'
+
+    # -------------------------------------------------------------------------
+    def __init__(
+        self, appname=None, base_dir=None, version=GLOBAL_VERSION,
+            cfg_class=ShowMailLdapConfiguration):
+
+        self.local_tz = None
+        self.local_tz_name = self.default_local_tz_name
+
+        description = _(
+            'Shows all relevant configured configured options for Mail and LDAP '
+            'supporting applications.')
+
+        super(ShowMailLdapConfigApp, self).__init__(
+            appname=appname, version=version, description=description, base_dir=base_dir,
+            cfg_class=cfg_class, initialized=False,
+        )
+
+    # -------------------------------------------------------------------------
+    def current_timestamp(self):
+
+        if self.local_tz:
+            return datetime.datetime.now(self.local_tz).strftime('%Y-%m-%d %H:%M:%S %Z')
+        return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+
+    # -------------------------------------------------------------------------
+    def post_init(self):
+
+        if not self.quiet:
+            print('')
+
+        LOG.debug(_("Post init phase."))
+
+        super(ShowMailLdapConfigApp, self).post_init()
+
+        LOG.debug(_("My own post init phase."))
+
+        if 'TZ' in os.environ and os.environ['TZ']:
+            self.local_tz_name = os.environ['TZ']
+        try:
+            self.local_tz = timezone(self.local_tz_name)
+        except UnknownTimeZoneError:
+            LOG.error(_("Unknown time zone: {!r}.").format(self.local_tz_name))
+            self.exit(6)
+
+    # -------------------------------------------------------------------------
+    def _run(self):
+
+        LOG.info(_("Starting: {}").format(self.current_timestamp()))
+
+
+# =============================================================================
+
+if __name__ == "__main__":
+
+    pass
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list