From 540ede1fdd3af7d45addcc59467f39a9aef6e6cb Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 6 Feb 2018 14:53:47 +0100 Subject: [PATCH] Applying flake8 rules to pp_lib/import_pdnsdata.py --- pp_lib/import_pdnsdata.py | 64 ++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/pp_lib/import_pdnsdata.py b/pp_lib/import_pdnsdata.py index 8e2ba92..93796f0 100644 --- a/pp_lib/import_pdnsdata.py +++ b/pp_lib/import_pdnsdata.py @@ -10,21 +10,16 @@ from __future__ import absolute_import # Standard modules -import os import logging import logging.config import re -import pwd import textwrap import traceback import socket -import ipaddress import datetime import time # Third party modules -import six - import psycopg2 import pymysql @@ -36,12 +31,12 @@ from .cfg_app import PpCfgAppError, PpConfigApplication from .pdns_record import PdnsSoaData -__version__ = '0.9.3' +__version__ = '0.9.4' LOG = logging.getLogger(__name__) # ============================================================================= class ImportPdnsdataError(PpCfgAppError): - pass; + pass # ============================================================================= class ImportPdnsdataApp(PpConfigApplication): @@ -68,7 +63,6 @@ class ImportPdnsdataApp(PpConfigApplication): # ------------------------------------------------------------------------- def __init__(self, appname=None, version=__version__): - description = textwrap.dedent('''\ Importing complete Database for PowerDNS from old DB into the new one. ''').strip() @@ -170,11 +164,12 @@ class ImportPdnsdataApp(PpConfigApplication): if 'host' in section: host = section['host'].lower().strip() if not host: - LOG.error('Invalid source hostname {!r} in configuration section {!r} found.'.format( - section['host'], section_name)) + LOG.error( + 'Invalid source hostname {!r} in configuration section {!r} found.'.format( + section['host'], section_name)) else: try: - _ = socket.getaddrinfo(host, 3306, proto=socket.IPPROTO_TCP) + _ = socket.getaddrinfo(host, 3306, proto=socket.IPPROTO_TCP) # noqa except socket.gaierror as e: msg = 'Invalid source hostname {!r} in configuration section {!r}: {}'.format( section['host'], section_name, e) @@ -192,7 +187,7 @@ class ImportPdnsdataApp(PpConfigApplication): raise ValueError("port number must be less than {}".format((2 ** 16))) except (ValueError, TypeError) as e: msg = 'Invalid source port number {!r} in configuration section {!r}: {}'.format( - section['port'],section_name, e) + section['port'], section_name, e) LOG.error(msg) self.config_has_errors = True else: @@ -201,16 +196,20 @@ class ImportPdnsdataApp(PpConfigApplication): if 'schema' in section: schema = section['schema'].lower().strip() if not schema: - LOG.error('Invalid source database name {!r} in configuration section {!r} found.'.format( - section['schema'], section_name)) + LOG.error(( + 'Invalid source database name {!r} ' + 'in configuration section {!r} found.').format( + section['schema'], section_name)) else: self.src_db_schema = schema if 'user' in section: user = section['user'].lower().strip() if not user: - LOG.error('Invalid source database user {!r} in configuration section {!r} found.'.format( - section['user'], section_name)) + LOG.error(( + 'Invalid source database user {!r} ' + 'in configuration section {!r} found.').format( + section['user'], section_name)) self.config_has_errors = True else: self.src_db_user = user @@ -242,12 +241,13 @@ class ImportPdnsdataApp(PpConfigApplication): if 'host' in section: host = section['host'].lower().strip() if not host: - LOG.error('Invalid target hostname {!r} in configuration section {!r} found.'.format( - section['host'], section_name)) + LOG.error( + 'Invalid target hostname {!r} in configuration section {!r} found.'.format( + section['host'], section_name)) self.config_has_errors = True else: try: - _ = socket.getaddrinfo(host, 3306, proto=socket.IPPROTO_TCP) + _ = socket.getaddrinfo(host, 3306, proto=socket.IPPROTO_TCP) # noqa except socket.gaierror as e: msg = 'Invalid target hostname {!r} in configuration section {!r}: {}'.format( section['host'], section_name, e) @@ -265,7 +265,7 @@ class ImportPdnsdataApp(PpConfigApplication): raise ValueError("port number must be less than {}".format((2 ** 16))) except (ValueError, TypeError) as e: msg = 'Invalid target port number {!r} in configuration section {!r}: {}'.format( - section['port'],section_name, e) + section['port'], section_name, e) LOG.error(msg) self.config_has_errors = True else: @@ -274,15 +274,19 @@ class ImportPdnsdataApp(PpConfigApplication): if 'schema' in section: schema = section['schema'].lower().strip() if not schema: - LOG.error('Invalid target database name {!r} in configuration section {!r} found.'.format( - section['schema'], section_name)) + LOG.error(( + 'Invalid target database name {!r} ' + 'in configuration section {!r} found.').format( + section['schema'], section_name)) else: self.tgt_db_schema = schema if 'user' in section: user = section['user'].lower().strip() if not user: - LOG.error('Invalid target database user {!r} in configuration section {!r} found.'.format( + LOG.error(( + 'Invalid target database user {!r} ' + 'in configuration section {!r} found.').format( section['user'], section_name)) self.config_has_errors = True else: @@ -341,7 +345,7 @@ class ImportPdnsdataApp(PpConfigApplication): else: self.connect_tgt_db_psql() - # ------------------------------------------------------------------------- + # ------------------------------------------------------------------------- def connect_tgt_db_mysql(self): result = None @@ -374,7 +378,7 @@ class ImportPdnsdataApp(PpConfigApplication): e.__class__.__name__, e)) self.exit(6) - # ------------------------------------------------------------------------- + # ------------------------------------------------------------------------- def connect_tgt_db_psql(self): result = None @@ -658,8 +662,9 @@ class ImportPdnsdataApp(PpConfigApplication): else: cur_account += ', local' if self.verbose > 1: - LOG.debug("Setting account information of zone {!r} to {!r}.".format( - result['name'], cur_account)) + LOG.debug( + "Setting account information of zone {!r} to {!r}.".format( + result['name'], cur_account)) result['account'] = cur_account if self.verbose > 1: LOG.debug("SQL for insert domain:\n{}".format( @@ -722,7 +727,6 @@ class ImportPdnsdataApp(PpConfigApplication): if self.verbose > 1: LOG.debug("Target SQL:\n{}".format(tgt_sql)) - with self.tgt_connection.cursor() as tgt_cursor: with self.src_connection.cursor() as src_cursor: @@ -792,7 +796,6 @@ class ImportPdnsdataApp(PpConfigApplication): if self.verbose > 1: LOG.debug("Target SQL:\n{}".format(tgt_sql)) - with self.tgt_connection.cursor() as tgt_cursor: with self.src_connection.cursor() as src_cursor: @@ -990,7 +993,6 @@ class ImportPdnsdataApp(PpConfigApplication): if self.verbose > 1: LOG.debug("Target SQL:\n{}".format(tgt_sql)) - with self.tgt_connection.cursor() as tgt_cursor: with self.src_connection.cursor() as src_cursor: @@ -1483,7 +1485,7 @@ class ImportPdnsdataApp(PpConfigApplication): soa = PdnsSoaData( primary=ns_used, email=mail_addr, serial=serial, refresh=refresh, retry=retry, expire=expire, ttl=ttl, - appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, + appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, ) LOG.debug("Inserting SOA {!r} ...".format(soa.data)) -- 2.39.5