]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Make the linter happy with lib/pp_admintools/config/pdns.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 14 Jun 2023 08:09:06 +0000 (10:09 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 14 Jun 2023 08:09:06 +0000 (10:09 +0200)
lib/pp_admintools/config/ldap.py
lib/pp_admintools/config/pdns.py

index 58a9b340d63f1cb6c963838a5c5ff05298bada54..10d478a8e284750aae071bc04fcf932cb39b221b 100644 (file)
@@ -463,7 +463,7 @@ class LdapConnectionDict(dict, FbGenericBaseObject):
 # =============================================================================
 class LdapConfiguration(PpBaseConfiguration):
     """
-    A class for providing a configuration for LDAP vased applications.
+    A class for providing a configuration for LDAP based applications.
 
     It provides also methods to read from configuration files.
     """
index a291ba9bfbd98112510ca10855489bbf1a9552e2..df43bcc50defef3f6b65bcbd2e65ba876a73df7f 100644 (file)
@@ -1,41 +1,36 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 """
+@summary: A module for providing a configuration for applications, which are Working with PowerDNS.
+
 @author: Frank Brehm
 @contact: frank.brehm@pixelpark.com
 @copyright: © 2023 by Frank Brehm, Berlin
-@summary: A module for providing a configuration for applications,
-          which are Working with PowerDNS.
-          It's based on class MailConfigError.
 """
 from __future__ import absolute_import
 
 # Standard module
+import copy
 import logging
 import re
-import copy
 
 # Third party modules
-
-# Own modules
-
 from fb_tools import MAX_TIMEOUT
 from fb_tools.common import is_sequence
 # from .config import ConfigError, BaseConfiguration
 from fb_tools.multi_config import DEFAULT_ENCODING
 
-from .. import __version__ as GLOBAL_VERSION
+# Own modules
+from .mail import DEFAULT_CONFIG_DIR
+from .mail import MailConfigError, MailConfiguration
 from .. import MAX_PORT_NUMBER
+from .. import __version__ as GLOBAL_VERSION
 from .. import pp
-
-from .mail import MailConfigError, MailConfiguration
-from .mail import DEFAULT_CONFIG_DIR
-
 from ..xlate import XLATOR
 
-LIBRARY_NAME = "pp-pdns-api-client"
+LIBRARY_NAME = 'pp-pdns-api-client'
 
-__version__ = '0.2.5'
+__version__ = '0.2.6'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -43,8 +38,7 @@ _ = XLATOR.gettext
 
 # =============================================================================
 class PdnsConfigError(MailConfigError):
-    """Base error class for all exceptions happened during
-    execution this configured application"""
+    """Base error class for all exceptions happened during execution a configured application."""
 
     pass
 
@@ -52,26 +46,27 @@ class PdnsConfigError(MailConfigError):
 # =============================================================================
 class PdnsConfiguration(MailConfiguration):
     """
-    A class for providing a configuration for an arbitrary PowerDNS Application
-    and methods to read it from configuration files.
+    A class for providing a configuration for an arbitrary PowerDNS application.
+
+    It provides also methods to read from configuration files.
     """
 
     valid_pdns_api_instances = ('global', 'public', 'local')
 
     default_pdns_api_instances = {
         'global': {
-            'host': "dnsmaster.pp-dns.com",
+            'host': 'dnsmaster.pp-dns.com',
         },
         'public': {
-            'host': "dnsmaster-public.pixelpark.com",
+            'host': 'dnsmaster-public.pixelpark.com',
         },
         'local': {
-            'host': "dnsmaster-local.pixelpark.com",
+            'host': 'dnsmaster-local.pixelpark.com',
         },
     }
 
     default_pdns_api_port = 8081
-    default_pdns_api_servername = "localhost"
+    default_pdns_api_servername = 'localhost'
     default_pdns_timeout = 20
 
     default_pdns_instance = 'global'
@@ -82,7 +77,7 @@ class PdnsConfiguration(MailConfiguration):
             append_appname_to_stems=True, additional_stems=None, config_dir=DEFAULT_CONFIG_DIR,
             additional_config_file=None, additional_cfgdirs=None, encoding=DEFAULT_ENCODING,
             ensure_privacy=True, use_chardet=True, initialized=False):
-
+        """Initialize the PdnsConfiguration object."""
         self.api_user_agent = '{}/{}'.format(LIBRARY_NAME, GLOBAL_VERSION)
 
         self.pdns_api_instances = {}
@@ -134,7 +129,7 @@ class PdnsConfiguration(MailConfiguration):
     # -------------------------------------------------------------------------
     def as_dict(self, short=True):
         """
-        Transforms the elements of the object into a dict
+        Transform the elements of the object into a dict.
 
         @param short: don't include local properties in resulting dict.
         @type short: bool
@@ -142,7 +137,6 @@ class PdnsConfiguration(MailConfiguration):
         @return: structure as dict
         @rtype:  dict
         """
-
         res = super(PdnsConfiguration, self).as_dict(short=short)
 
         res['default_pdns_api_instances'] = self.default_pdns_api_instances
@@ -171,7 +165,7 @@ class PdnsConfiguration(MailConfiguration):
 
     # -------------------------------------------------------------------------
     def eval_section(self, section_name):
-
+        """Evaluate a particular configuration section."""
         super(PdnsConfiguration, self).eval_section(section_name)
         sn = section_name.lower()
 
@@ -185,7 +179,7 @@ class PdnsConfiguration(MailConfiguration):
     def _eval_pdns(self, section_name, section):
 
         if self.verbose > 2:
-            msg = _("Evaluating config section {!r}:").format(section_name)
+            msg = _('Evaluating config section {!r}:').format(section_name)
             LOG.debug(msg + '\n' + pp(section))
 
         re_agent = re.compile(r'^\s*(?:api[_-]?)?user[_-]?agent\s*$', re.IGNORECASE)
@@ -245,12 +239,12 @@ class PdnsConfiguration(MailConfiguration):
         try:
             timeout = int(val)
             if timeout <= 0 or timeout > MAX_TIMEOUT:
-                msg = _("A timeout has to be between 1 and {} seconds.")
+                msg = _('A timeout has to be between 1 and {} seconds.')
                 msg = msg.format(MAX_TIMEOUT)
                 raise ValueError(msg)
         except (ValueError, TypeError) as e:
-            msg = _("Value {!r} for PowerDNS API timeout is invalid:").format(val)
-            msg += " " + str(e)
+            msg = _('Value {!r} for PowerDNS API timeout is invalid:').format(val)
+            msg += ' ' + str(e)
             if self.raise_on_error:
                 raise PdnsConfigError(msg)
             LOG.error(msg)
@@ -267,7 +261,7 @@ class PdnsConfiguration(MailConfiguration):
             return
 
         if env not in self.pdns_api_instances:
-            msg = _("Found invalid PDNS environment/instance {!r} in configuration.")
+            msg = _('Found invalid PDNS environment/instance {!r} in configuration.')
             msg = msg.format(section[key])
             if self.raise_on_error:
                 raise PdnsConfigError(msg)
@@ -282,7 +276,7 @@ class PdnsConfiguration(MailConfiguration):
         val = section[key].strip().lower()
         if val:
             if self.verbose > 2:
-                msg = _("Found PDNS host: {!r}.").format(val)
+                msg = _('Found PDNS host: {!r}.').format(val)
                 LOG.debug(msg)
 
             self.pdns_host = val
@@ -298,10 +292,10 @@ class PdnsConfiguration(MailConfiguration):
         try:
             port = int(val)
             if port <= 0 or port > MAX_PORT_NUMBER:
-                msg = _("A port must be greater than 0 and less than {}.")
+                msg = _('A port must be greater than 0 and less than {}.')
                 raise ValueError(msg.format(MAX_PORT_NUMBER))
         except (TypeError, ValueError) as e:
-            msg = _("Wrong PDNS port number {p!r} found: {e}").format(p=val, e=e)
+            msg = _('Wrong PDNS port number {p!r} found: {e}').format(p=val, e=e)
             if self.raise_on_error:
                 raise PdnsConfigError(msg)
             else:
@@ -310,7 +304,7 @@ class PdnsConfiguration(MailConfiguration):
 
         if port:
             if self.verbose > 2:
-                msg = _("Found port number for PDNS: {}.").format(port)
+                msg = _('Found port number for PDNS: {}.').format(port)
                 LOG.debug(msg)
 
             self.pdns_port = port
@@ -324,7 +318,7 @@ class PdnsConfiguration(MailConfiguration):
                 key_show = '******'
                 if self.verbose > 4:
                     key_show = val
-                msg = _("Found API key for PDNS: {!r}.").format(key_show)
+                msg = _('Found API key for PDNS: {!r}.').format(key_show)
                 LOG.debug(msg)
 
             self.pdns_key = val
@@ -335,7 +329,7 @@ class PdnsConfiguration(MailConfiguration):
         val = section[key].strip()
         if val:
             if self.verbose > 2:
-                msg = _("Found PDNS API servername: {!r}.").format(val)
+                msg = _('Found PDNS API servername: {!r}.').format(val)
                 LOG.debug(msg)
 
             self.pdns_servername = val
@@ -352,7 +346,7 @@ class PdnsConfiguration(MailConfiguration):
         iname = instance_name.lower()
 
         if self.verbose > 2:
-            msg = _("Evaluating PowerDNS instance {!r}:").format(iname)
+            msg = _('Evaluating PowerDNS instance {!r}:').format(iname)
             LOG.debug(msg + '\n' + pp(section))
 
         self._eval_pdns_inst_host(iname, section)
@@ -364,7 +358,7 @@ class PdnsConfiguration(MailConfiguration):
     def _eval_pdns_inst_host(self, iname, section):
 
         if self.verbose > 2:
-            msg = _("Searching for host for PDNS instance {!r} ..")
+            msg = _('Searching for host for PDNS instance {!r} ..')
             LOG.debug(msg.format(iname))
 
         for key in section.keys():
@@ -372,7 +366,7 @@ class PdnsConfiguration(MailConfiguration):
                 host = section[key].lower().strip()
                 if host:
                     if self.verbose > 2:
-                        msg = _("Found host for PDNS instance {inst!r}: {host!r}.")
+                        msg = _('Found host for PDNS instance {inst!r}: {host!r}.')
                         LOG.debug(msg.format(inst=iname, host=host))
                     self.pdns_api_instances[iname]['host'] = host
 
@@ -380,7 +374,7 @@ class PdnsConfiguration(MailConfiguration):
     def _eval_pdns_inst_port(self, iname, section):
 
         if self.verbose > 2:
-            msg = _("Searching for post number for PDNS instance {!r} ..")
+            msg = _('Searching for post number for PDNS instance {!r} ..')
             LOG.debug(msg.format(iname))
 
         for key in section.keys():
@@ -390,10 +384,10 @@ class PdnsConfiguration(MailConfiguration):
                 try:
                     port = int(val)
                     if port <= 0 or port > MAX_PORT_NUMBER:
-                        msg = _("A port must be greater than 0 and less than {}.")
+                        msg = _('A port must be greater than 0 and less than {}.')
                         raise ValueError(msg.format(MAX_PORT_NUMBER))
                 except (TypeError, ValueError) as e:
-                    msg = _("Wrong port number {p!r} for PDNS instance {inst!r} found: {e}")
+                    msg = _('Wrong port number {p!r} for PDNS instance {inst!r} found: {e}')
                     msg = msg.format(p=val, inst=iname, e=e)
                     if self.raise_on_error:
                         raise PdnsConfigError(msg)
@@ -402,7 +396,7 @@ class PdnsConfiguration(MailConfiguration):
                         port = None
                 if port:
                     if self.verbose > 2:
-                        msg = _("Found port number for PDNS instance {inst!r}: {p}.")
+                        msg = _('Found port number for PDNS instance {inst!r}: {p}.')
                         LOG.debug(msg.format(inst=iname, p=port))
                     self.pdns_api_instances[iname]['port'] = port
 
@@ -410,7 +404,7 @@ class PdnsConfiguration(MailConfiguration):
     def _eval_pdns_inst_servername(self, iname, section):
 
         if self.verbose > 2:
-            msg = _("Searching for internal server name of PDNS instance {!r} ..")
+            msg = _('Searching for internal server name of PDNS instance {!r} ..')
             LOG.debug(msg.format(iname))
 
         re_servername = re.compile(r'^\s*server[_-]?(name|id)\s*$', re.IGNORECASE)
@@ -420,7 +414,7 @@ class PdnsConfiguration(MailConfiguration):
                 servername = section[key].lower().strip()
                 if servername:
                     if self.verbose > 2:
-                        msg = _("Found internal server name PDNS instance {inst!r}: {sn!r}.")
+                        msg = _('Found internal server name PDNS instance {inst!r}: {sn!r}.')
                         LOG.debug(msg.format(inst=iname, sn=servername))
                     self.pdns_api_instances[iname]['servername'] = servername
 
@@ -428,7 +422,7 @@ class PdnsConfiguration(MailConfiguration):
     def _eval_pdns_inst_key(self, iname, section):
 
         if self.verbose > 2:
-            msg = _("Searching for API key of PDNS instance {!r} ..")
+            msg = _('Searching for API key of PDNS instance {!r} ..')
             LOG.debug(msg.format(iname))
 
         re_key = re.compile(r'^\s*(api[_-]?)?key\s*$', re.IGNORECASE)
@@ -441,13 +435,13 @@ class PdnsConfiguration(MailConfiguration):
                         key_show = '******'
                         if self.verbose > 4:
                             key_show = api_key
-                        msg = _("Found API key of PDNS instance {inst!r}: {key!r}.")
+                        msg = _('Found API key of PDNS instance {inst!r}: {key!r}.')
                         LOG.debug(msg.format(inst=iname, key=key_show))
                     self.pdns_api_instances[iname]['key'] = api_key
 
     # -------------------------------------------------------------------------
-    def eval(self):
-
+    def eval(self):                                                             # noqa: A003
+        """Evaluate the complete given configuration hash."""
         super(PdnsConfiguration, self).eval()
 
         inst = self.pdns_instance
@@ -466,7 +460,7 @@ class PdnsConfiguration(MailConfiguration):
 
 
 # =============================================================================
-if __name__ == "__main__":
+if __name__ == '__main__':
 
     pass