From: Frank Brehm Date: Tue, 13 Jun 2023 12:54:00 +0000 (+0200) Subject: Make the linter happy with lib/pp_admintools/config/dns_deploy_zones.py X-Git-Tag: 0.10.0^2~18 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=c77b944e8df2f2bbcb240312a29b2448456a9946;p=pixelpark%2Fpp-admin-tools.git Make the linter happy with lib/pp_admintools/config/dns_deploy_zones.py --- diff --git a/lib/pp_admintools/config/dns_deploy_zones.py b/lib/pp_admintools/config/dns_deploy_zones.py index 1588824..67949b7 100644 --- a/lib/pp_admintools/config/dns_deploy_zones.py +++ b/lib/pp_admintools/config/dns_deploy_zones.py @@ -1,39 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ +@summary: A module for providing a configuration the dns-deploy-zones applications. + + It's based on class PdnsConfiguration. + @author: Frank Brehm @contact: frank.brehm@pixelpark.com @copyright: © 2023 by Frank Brehm, Berlin -@summary: A module for providing a configuration the dns-deploy-zones applications. - It's based on class PdnsConfiguration. """ from __future__ import absolute_import # Standard module +import copy import logging import re -import copy import socket - from pathlib import Path # Third party modules - -# Own modules - from fb_tools.common import is_sequence, to_bool - -# from .config import ConfigError, BaseConfiguration from fb_tools.multi_config import DEFAULT_ENCODING -from .pdns import PdnsConfigError, PdnsConfiguration +# Own modules +# from .config import ConfigError, BaseConfiguration from .mail import DEFAULT_CONFIG_DIR - +from .pdns import PdnsConfigError, PdnsConfiguration from .. import pp - from ..xlate import XLATOR -__version__ = '0.2.3' +__version__ = '0.2.4' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -41,8 +37,7 @@ _ = XLATOR.gettext # ============================================================================= class DnsDeployZonesConfigError(PdnsConfigError): - """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 @@ -50,8 +45,9 @@ class DnsDeployZonesConfigError(PdnsConfigError): # ============================================================================= class DnsDeployZonesConfig(PdnsConfiguration): """ - 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. """ default_pidfile = Path('/run/dns-deploy-zones.pid') @@ -80,7 +76,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): 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 DnsDeployZonesConfig object.""" self.pidfile = self.default_pidfile self.keep_backup = self.default_keep_backup @@ -131,8 +127,11 @@ class DnsDeployZonesConfig(PdnsConfiguration): # ------------------------------------------------------------------------- @property def named_internal(self): - """Is the BIND nameserver on the current host a local resolver (True) - or an authoritative nameserver for outside.""" + """ + Return, whether the BIND nameserver is used as a local resolver. + + Otherwise the BIND nameserver is used as an authoritative nameserver for outside. + """ return self._named_internal @named_internal.setter @@ -142,7 +141,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): # ------------------------------------------------------------------------- @property def named_listen_on_v6(self): - """Is the BIND nameserver on the current listening on some IPv6 addresses?""" + """Return, whether the BIND nameserver on the current listening on some IPv6 addresses.""" return self._named_listen_on_v6 @named_listen_on_v6.setter @@ -152,7 +151,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): # ------------------------------------------------------------------------- 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 @@ -160,7 +159,6 @@ class DnsDeployZonesConfig(PdnsConfiguration): @return: structure as dict @rtype: dict """ - res = super(DnsDeployZonesConfig, self).as_dict(short=short) res['default_pidfile'] = self.default_pidfile @@ -185,7 +183,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): # ------------------------------------------------------------------------- def eval_section(self, section_name): - + """Evaluate a particular configuration section.""" super(DnsDeployZonesConfig, self).eval_section(section_name) sn = section_name.lower() @@ -201,7 +199,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): def _eval_named(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_config_dir = re.compile(r'^\s*(?:named[_-]?)?conf(?:ig)?[_-]?dir\s*$', re.IGNORECASE) @@ -289,7 +287,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): m = m.strip().lower() if self.verbose > 1: - LOG.debug(_("Checking given master address {!r} ...").format(m)) + LOG.debug(_('Checking given master address {!r} ...').format(m)) addr_list = self.get_addresses(m) masters |= addr_list @@ -297,11 +295,11 @@ class DnsDeployZonesConfig(PdnsConfiguration): # ------------------------------------------------------------------------- def get_addresses(self, host): - + """Try to evaluate all IP addresses of the given hostname.""" addr_list = set() if self.verbose > 3: - msg = _("Trying to evaluate address of host {!r} ...").format(host) + msg = _('Trying to evaluate address of host {!r} ...').format(host) LOG.debug(msg) try: @@ -310,7 +308,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): addr = addr_info[4][0] addr_list.add(addr) except socket.gaierror as e: - msg = _("Invalid hostname or address {a!r} found in masters: {e}") + msg = _('Invalid hostname or address {a!r} found in masters: {e}') msg = msg.format(a=host, e=e) if self.raise_on_error: raise DnsDeployZonesConfigError(msg) @@ -318,7 +316,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): LOG.error(msg) return set() if self.verbose > 3: - msg = _("Got addresses {a!r} for host {h!r}.") + msg = _('Got addresses {a!r} for host {h!r}.') LOG.debug(msg.format(a=addr_list, h=host)) return addr_list @@ -332,7 +330,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): path = Path(val) if not path.is_absolute(): - msg = _("The path to {what} must be an absolute path, found {path!r}.") + msg = _('The path to {what} must be an absolute path, found {path!r}.') msg = msg.format(what='rndc', path=val) if self.raise_on_error: raise DnsDeployZonesConfigError(msg) @@ -341,7 +339,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): return if self.verbose > 2: - msg = _("Found path to {what}: {path!r}.").format(what='rndc', path=val) + msg = _('Found path to {what}: {path!r}.').format(what='rndc', path=val) LOG.debug(msg) self.rndc = path @@ -355,7 +353,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): path = Path(val) if not path.is_absolute(): - msg = _("The path to {what} must be an absolute path, found {path!r}.") + msg = _('The path to {what} must be an absolute path, found {path!r}.') msg = msg.format(what='systemctl', path=val) if self.raise_on_error: raise DnsDeployZonesConfigError(msg) @@ -364,7 +362,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): return if self.verbose > 2: - msg = _("Found path to {what}: {path!r}.").format(what='systemctl', path=val) + msg = _('Found path to {what}: {path!r}.').format(what='systemctl', path=val) LOG.debug(msg) self.systemctl = path @@ -376,11 +374,11 @@ class DnsDeployZonesConfig(PdnsConfiguration): if not val: return - what = _("the named config directory") + what = _('the named config directory') path = Path(val) if not path.is_absolute(): - msg = _("The path to {what} must be an absolute path, found {path!r}.") + msg = _('The path to {what} must be an absolute path, found {path!r}.') msg = msg.format(what=what, path=val) if self.raise_on_error: raise DnsDeployZonesConfigError(msg) @@ -389,7 +387,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): return if self.verbose > 2: - msg = _("Found path to {what}: {path!r}.").format(what=what, path=val) + msg = _('Found path to {what}: {path!r}.').format(what=what, path=val) LOG.debug(msg) self.named_conf_dir = path @@ -401,11 +399,11 @@ class DnsDeployZonesConfig(PdnsConfiguration): if not val: return - what = _("the named config file for zones") + what = _('the named config file for zones') path = Path(val) if path.is_absolute(): - msg = _("The path to {what} must not be an absolute path, found {path!r}.") + msg = _('The path to {what} must not be an absolute path, found {path!r}.') msg = msg.format(what=what, path=val) if self.raise_on_error: raise DnsDeployZonesConfigError(msg) @@ -414,7 +412,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): return if self.verbose > 2: - msg = _("Found path to {what}: {path!r}.").format(what=what, path=val) + msg = _('Found path to {what}: {path!r}.').format(what=what, path=val) LOG.debug(msg) self.named_zones_cfg_file = path @@ -426,10 +424,10 @@ class DnsDeployZonesConfig(PdnsConfiguration): if not val: return - what = _("the named base directory") + what = _('the named base directory') path = Path(val) if not path.is_absolute(): - msg = _("The path to {what} must be an absolute path, found {path!r}.") + msg = _('The path to {what} must be an absolute path, found {path!r}.') msg = msg.format(what=what, path=val) if self.raise_on_error: raise DnsDeployZonesConfigError(msg) @@ -438,7 +436,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): return if self.verbose > 2: - msg = _("Found path to {what}: {path!r}.").format(what=what, path=val) + msg = _('Found path to {what}: {path!r}.').format(what=what, path=val) LOG.debug(msg) self.named_basedir = path @@ -450,11 +448,11 @@ class DnsDeployZonesConfig(PdnsConfiguration): if not val: return - what = _("the directory for slave zones of named") + what = _('the directory for slave zones of named') path = Path(val) if path.is_absolute(): - msg = _("The path to {what} must not be an absolute path, found {path!r}.") + msg = _('The path to {what} must not be an absolute path, found {path!r}.') msg = msg.format(what=what, path=val) if self.raise_on_error: raise DnsDeployZonesConfigError(msg) @@ -463,7 +461,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): return if self.verbose > 2: - msg = _("Found path to {what}: {path!r}.").format(what=what, path=val) + msg = _('Found path to {what}: {path!r}.').format(what=what, path=val) LOG.debug(msg) self.named_slavedir = path @@ -475,10 +473,10 @@ class DnsDeployZonesConfig(PdnsConfiguration): if not val: return - what = "named-checkconf" + what = 'named-checkconf' path = Path(val) if not path.is_absolute(): - msg = _("The path to {what} must be an absolute path, found {path!r}.") + msg = _('The path to {what} must be an absolute path, found {path!r}.') msg = msg.format(what=what, path=val) if self.raise_on_error: raise DnsDeployZonesConfigError(msg) @@ -487,7 +485,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): return if self.verbose > 2: - msg = _("Found path to {what}: {path!r}.").format(what=what, path=val) + msg = _('Found path to {what}: {path!r}.').format(what=what, path=val) LOG.debug(msg) self.named_checkconf = path @@ -514,7 +512,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): def _eval_app(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_pidfile = re.compile(r'^\s*pid[_-]?file$', re.IGNORECASE) @@ -537,10 +535,10 @@ class DnsDeployZonesConfig(PdnsConfiguration): if not val: return - what = _("the PID file") + what = _('the PID file') path = Path(val) if not path.is_absolute(): - msg = _("The path to {what} must be an absolute path, found {path!r}.") + msg = _('The path to {what} must be an absolute path, found {path!r}.') msg = msg.format(what=what, path=val) if self.raise_on_error: raise DnsDeployZonesConfigError(msg) @@ -549,7 +547,7 @@ class DnsDeployZonesConfig(PdnsConfiguration): return if self.verbose > 2: - msg = _("Found path to {what}: {path!r}.").format(what=what, path=val) + msg = _('Found path to {what}: {path!r}.').format(what=what, path=val) LOG.debug(msg) self.pidfile = path @@ -564,9 +562,8 @@ class DnsDeployZonesConfig(PdnsConfiguration): self.keep_backup = to_bool(val) # ------------------------------------------------------------------------- - def eval(self): - """Evaluating read configuration and storing them in object properties.""" - + def eval(self): # noqa: A003 + """Evaluate read configuration and storing it in object properties.""" super(DnsDeployZonesConfig, self).eval() addr_list = set() @@ -589,17 +586,17 @@ class DnsDeployZonesConfig(PdnsConfiguration): if self.masters: if self.verbose > 2: - LOG.debug(_("Using configured masters:") + '\n' + pp(self.masters)) + LOG.debug(_('Using configured masters:') + '\n' + pp(self.masters)) else: - LOG.warn(_("No valid masters found in configuration.")) + LOG.warn(_('No valid masters found in configuration.')) if self.verbose > 2: - msg = _("Evaluated configuration:") - msg += " " + pp(self.as_dict()) + msg = _('Evaluated configuration:') + msg += ' ' + pp(self.as_dict()) # ============================================================================= -if __name__ == "__main__": +if __name__ == '__main__': pass