From: Frank Brehm Date: Tue, 6 Feb 2018 15:03:53 +0000 (+0100) Subject: Applying flake8 rules to pp_lib/config_named_app.py X-Git-Tag: 0.1.2~6^2~28 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=afc03b474c17cea0d18665dd11ef3babec888719;p=pixelpark%2Fadmin-tools.git Applying flake8 rules to pp_lib/config_named_app.py --- diff --git a/pp_lib/config_named_app.py b/pp_lib/config_named_app.py index eee79b7..6b4db7a 100644 --- a/pp_lib/config_named_app.py +++ b/pp_lib/config_named_app.py @@ -14,38 +14,34 @@ import logging import logging.config import re import pwd -import glob import copy import textwrap import socket -import pwd import grp import tempfile import time import datetime -import textwrap import ipaddress import stat import shutil -import shlex, subprocess +import shlex from subprocess import Popen, TimeoutExpired, PIPE # Third party modules import six -from six import reraise import requests from six.moves.urllib.parse import urlunsplit # Own modules -from .common import pp, to_bool, to_bytes, to_str +from .common import pp, to_bool, to_str from .cfg_app import PpCfgAppError, PpConfigApplication -from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile +from .pidfile import PidFileError, PidFile -__version__ = '0.7.3' +__version__ = '0.7.4' LOG = logging.getLogger(__name__) @@ -206,26 +202,26 @@ class PpConfigNamedApp(PpConfigApplication): log_categories = { 'client': ['null'], - 'config': ['syslog', 'named', 'config',], - 'database': ['syslog', 'named',], - 'default': ['syslog', 'named',], - 'delegation-only': ['syslog', 'named',], - 'dispatch': ['syslog', 'named',], - 'dnssec': ['syslog', 'named', 'dnssec',], - 'general': ['syslog', 'named',], + 'config': ['syslog', 'named', 'config'], + 'database': ['syslog', 'named'], + 'default': ['syslog', 'named'], + 'delegation-only': ['syslog', 'named'], + 'dispatch': ['syslog', 'named'], + 'dnssec': ['syslog', 'named', 'dnssec'], + 'general': ['syslog', 'named'], 'lame-servers': ['lame-servers'], - 'network': ['syslog', 'named', 'network',], - 'notify': ['syslog', 'named', 'notify',], - 'queries': ['query', 'query-error',], - 'resolver': ['syslog', 'named', 'resolver',], - 'rpz': ['syslog', 'named',], - 'rate-limit': ['syslog', 'named', 'ratelimit',], - 'security': ['syslog', 'named', 'security',], - 'unmatched': ['syslog', 'named', 'unmatched',], - 'update': ['syslog', 'named', 'update',], - 'update-security': ['syslog', 'named', 'update', 'security',], - 'xfer-in': ['syslog', 'named', 'xfer-in',], - 'xfer-out': ['syslog', 'named', 'xfer-out',], + 'network': ['syslog', 'named', 'network'], + 'notify': ['syslog', 'named', 'notify'], + 'queries': ['query', 'query-error'], + 'resolver': ['syslog', 'named', 'resolver'], + 'rpz': ['syslog', 'named'], + 'rate-limit': ['syslog', 'named', 'ratelimit'], + 'security': ['syslog', 'named', 'security'], + 'unmatched': ['syslog', 'named', 'unmatched'], + 'update': ['syslog', 'named', 'update'], + 'update-security': ['syslog', 'named', 'update', 'security'], + 'xfer-in': ['syslog', 'named', 'xfer-in'], + 'xfer-out': ['syslog', 'named', 'xfer-out'], } # ------------------------------------------------------------------------- @@ -255,16 +251,16 @@ class PpConfigNamedApp(PpConfigApplication): self._named_zones_cfg_file = self.default_named_zones_cfg_file # Variable status directories and files - self.named_basedir = self.default_named_basedir - self._named_datadir = self.default_named_datadir - self._named_slavedir = self.default_named_slavedir - self._named_managed_keysdir = self.default_named_managed_keysdir - self._named_root_zone_file = self.default_named_root_zone_file + self.named_basedir = self.default_named_basedir + self._named_datadir = self.default_named_datadir + self._named_slavedir = self.default_named_slavedir + self._named_managed_keysdir = self.default_named_managed_keysdir + self._named_root_zone_file = self.default_named_root_zone_file # Runtime volatile directories and files - self.named_rundir = self.default_named_rundir - self._named_pidfile = self.default_named_pidfile - self._named_session_keyfile = self.default_named_session_keyfile + self.named_rundir = self.default_named_rundir + self._named_pidfile = self.default_named_pidfile + self._named_session_keyfile = self.default_named_session_keyfile # Runtime user and group self.named_user = 'named' @@ -572,7 +568,7 @@ class PpConfigNamedApp(PpConfigApplication): if section_name.lower() in ( 'powerdns-api', 'powerdns_api', 'powerdnsapi', - 'pdns-api', 'pdns_api', 'pdnsapi' ): + 'pdns-api', 'pdns_api', 'pdnsapi'): self.set_api_options(section, section_name) if section_name.lower() == 'named': @@ -618,8 +614,9 @@ class PpConfigNamedApp(PpConfigApplication): raise ValueError( "a port must be greater than 0 and less than {}.".format(2**16)) except (TypeError, ValueError) as e: - LOG.error("Wrong port number {!r} in configuration section {!r}: {}".format( - section['port'], section_name, e)) + LOG.error( + "Wrong port number {!r} in configuration section {!r}: {}".format( + section['port'], section_name, e)) self.config_has_errors = True else: self.pdns_api_port = port @@ -752,8 +749,8 @@ class PpConfigNamedApp(PpConfigApplication): if m: m = m.strip().lower() try: - addr_info = socket.getaddrinfo( - m, 53, proto=socket.IPPROTO_TCP, family=socket.AF_INET) + addr_info = socket.getaddrinfo( # noqa + m, 53, proto=socket.IPPROTO_TCP, family=socket.AF_INET) # noqa except socket.gaierror as e: msg = ( "Invalid hostname or address {!r} found in " @@ -992,7 +989,7 @@ class PpConfigNamedApp(PpConfigApplication): LOG.debug("Generated {!r}:\n{}".format(self.temp_acl_cfg_file, content.strip())) # ------------------------------------------------------------------------- - def generate_named_conf(self): + def generate_named_conf(self): # noqa LOG.info("Generating {} ...".format(self.default_named_conf)) @@ -1145,7 +1142,7 @@ class PpConfigNamedApp(PpConfigApplication): LOG.debug("Generated {!r}:\n{}".format(self.temp_named_conf, content.strip())) # ------------------------------------------------------------------------- - def generate_log_cfg_file(self): + def generate_log_cfg_file(self): # noqa LOG.info("Generating {} ...".format(self.default_named_log_cfg_file)) @@ -1164,7 +1161,7 @@ class PpConfigNamedApp(PpConfigApplication): content = header - content += '\nlogging {\n'; + content += '\nlogging {\n' content += '\n\t// -----------------------------------\n' content += '\t// Channels\n' @@ -1223,7 +1220,7 @@ class PpConfigNamedApp(PpConfigApplication): channels = ['null'] if cat_name == 'queries': if self.query_log: - if not 'query' in channels: + if 'query' not in channels: channels.append('query') else: if 'query' in channels: @@ -1309,7 +1306,6 @@ class PpConfigNamedApp(PpConfigApplication): if self.verbose > 2: LOG.debug("Generated {!r}:\n{}".format(self.temp_zones_cfg_file, content.strip())) - # ------------------------------------------------------------------------- def get_api_zones(self): @@ -1353,16 +1349,16 @@ class PpConfigNamedApp(PpConfigApplication): for entry in json_response: -# { 'account': '', -# 'dnssec': False, -# 'id': '56.66.217.in-addr.arpa.', -# 'kind': 'Master', -# 'last_check': 0, -# 'masters': [], -# 'name': '56.66.217.in-addr.arpa.', -# 'notified_serial': 2017080202, -# 'serial': 2017080202, -# 'url': 'api/v1/servers/localhost/zones/56.66.217.in-addr.arpa.'}, + # { 'account': '', + # 'dnssec': False, + # 'id': '56.66.217.in-addr.arpa.', + # 'kind': 'Master', + # 'last_check': 0, + # 'masters': [], + # 'name': '56.66.217.in-addr.arpa.', + # 'notified_serial': 2017080202, + # 'serial': 2017080202, + # 'url': 'api/v1/servers/localhost/zones/56.66.217.in-addr.arpa.'}, zone_name = entry['name'] zone = { @@ -1543,7 +1539,6 @@ class PpConfigNamedApp(PpConfigApplication): def check_directories(self): LOG.info("Checking all necessary directories for existence and ownership.") - all_ok = True self.check_directory(self.named_conf_dir) self.check_directory(self.named_basedir, None, self.named_gid, 0o750) @@ -1555,7 +1550,7 @@ class PpConfigNamedApp(PpConfigApplication): self.check_directory(self.named_logdir, self.named_uid, self.named_gid, 0o755) # ------------------------------------------------------------------------- - def check_directory(self, dirname, owner_id=None, group_id=None, mode=None): + def check_directory(self, dirname, owner_id=None, group_id=None, mode=None): # noqa LOG.debug("Checking directory {!r} ...".format(dirname))