From: Frank Brehm Date: Fri, 22 Jan 2021 13:40:22 +0000 (+0100) Subject: Transforming bin/dns-deploy-zones to the new schema X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=d21f544275ca31c5e4622bb13a03969e09bced3b;p=pixelpark%2Fadmin-tools.git Transforming bin/dns-deploy-zones to the new schema --- diff --git a/bin/barracuda-sync b/bin/barracuda-sync index 5f3e66c..4a19aee 100755 --- a/bin/barracuda-sync +++ b/bin/barracuda-sync @@ -4,7 +4,6 @@ from __future__ import print_function # Standard modules import sys -import gettext __exp_py_version_major__ = 3 __min_py_version_minor__ = 4 diff --git a/bin/dns-deploy-zones b/bin/dns-deploy-zones index 3a038c5..0d17aa8 100755 --- a/bin/dns-deploy-zones +++ b/bin/dns-deploy-zones @@ -1,31 +1,54 @@ #!/usr/bin/env python3 +from __future__ import print_function + # Standard modules import sys + +__exp_py_version_major__ = 3 +__min_py_version_minor__ = 4 + +if sys.version_info[0] != __exp_py_version_major__: + print("This script is intended to use with Python {}.".format( + __exp_py_version_major__), file=sys.stderr) + print("You are using Python: {0}.{1}.{2}-{3}-{4}.".format( + *sys.version_info) + "\n", file=sys.stderr) + sys.exit(1) + +if sys.version_info[1] < __min_py_version_minor__: + print("A minimal Python version of {maj}.{min} is necessary to execute this script.".format( + maj=__exp_py_version_major__, min=__min_py_version_minor__), file=sys.stderr) + print("You are using Python: {0}.{1}.{2}-{3}-{4}.".format( + *sys.version_info) + "\n", file=sys.stderr) + sys.exit(1) + +# Standard modules import os -import logging import locale +try: + import pathlib + from pathlib import Path +except ImportError: + from pathlib2 import Path + import pathlib2 as pathlib + # own modules: -cur_dir = os.getcwd() -base_dir = cur_dir - -if sys.argv[0] != '' and sys.argv[0] != '-c': - bin_dir = os.path.dirname(os.path.realpath(sys.argv[0])) -else: - bin_dir = os.path.dirname(os.path.realpath(__file__)) -base_dir = os.path.abspath(os.path.join(bin_dir, '..')) -module_dir = os.path.join(base_dir, 'pp_lib') -if os.path.exists(module_dir): - sys.path.insert(0, base_dir) - -#from pp_lib.config_named_app import PpConfigNamedApp -from pp_lib.deploy_zones_from_pdns import PpDeployZonesApp -log = logging.getLogger(__name__) +my_path = Path(__file__) +my_real_path = my_path.resolve() +bin_path = my_real_path.parent +base_dir = bin_path.parent +lib_dir = base_dir.joinpath('lib') +module_dir = lib_dir.joinpath('pp_lib') + +if module_dir.exists(): + sys.path.insert(0, str(lib_dir)) + +from pp_lib.deploy_zones_from_pdns import PpDeployZonesApp __author__ = 'Frank Brehm ' -__copyright__ = '(C) 2018 by Frank Brehm, Pixelpark GmbH, Berlin' +__copyright__ = '(C) 2021 by Frank Brehm, Pixelpark GmbH, Berlin' appname = os.path.basename(sys.argv[0]) diff --git a/lib/pp_lib/deploy_zones_from_pdns.py b/lib/pp_lib/deploy_zones_from_pdns.py index 4c404d0..d189431 100644 --- a/lib/pp_lib/deploy_zones_from_pdns.py +++ b/lib/pp_lib/deploy_zones_from_pdns.py @@ -3,7 +3,7 @@ """ @author: Frank Brehm @contact: frank.brehm@pixelpark.com -@copyright: © 2018 by Frank Brehm, Berlin +@copyright: © 2021 by Frank Brehm, Berlin @summary: A module for the application class for configuring named """ from __future__ import absolute_import @@ -31,13 +31,13 @@ import six from pytz import timezone, UnknownTimeZoneError # Own modules -from .common import pp, compare_fqdn, to_str, to_bool +from fb_tools.common import pp, compare_fqdn, to_str, to_bool from .pdns_app import PpPDNSAppError, PpPDNSApplication from .pidfile import PidFileError, PidFile -__version__ = '0.5.4' +__version__ = '0.5.5' LOG = logging.getLogger(__name__) diff --git a/lib/pp_lib/pdns_app.py b/lib/pp_lib/pdns_app.py index 1cda9a9..6cd4385 100644 --- a/lib/pp_lib/pdns_app.py +++ b/lib/pp_lib/pdns_app.py @@ -3,7 +3,7 @@ """ @author: Frank Brehm @contact: frank.brehm@pixelpark.com -@copyright: © 2018 by Frank Brehm, Berlin +@copyright: © 2021 by Frank Brehm, Berlin @summary: The module for a application object related to PowerDNS. """ from __future__ import absolute_import @@ -25,13 +25,13 @@ import requests import psutil # Own modules -from .common import pp +from fb_tools.common import pp from .cfg_app import PpCfgAppError, PpConfigApplication from .pdns_zone import PdnsApiZone from .pdns_record import PdnsSoaData -__version__ = '0.6.5' +__version__ = '0.6.6' LOG = logging.getLogger(__name__) _LIBRARY_NAME = "pp-pdns-api-client" diff --git a/lib/pp_lib/pdns_record.py b/lib/pp_lib/pdns_record.py index 17a29fc..886b2d6 100644 --- a/lib/pp_lib/pdns_record.py +++ b/lib/pp_lib/pdns_record.py @@ -17,11 +17,10 @@ import datetime # Third party modules # Own modules -from .common import pp, compare_fqdn, to_utf8, to_str +from fb_tools.common import pp, compare_fqdn, to_utf8, to_str +from fb_tools.obj import FbBaseObjectError, FbBaseObject -from .obj import PpBaseObjectError, PpBaseObject - -__version__ = '0.4.6' +__version__ = '0.4.7' LOG = logging.getLogger(__name__) @@ -40,7 +39,7 @@ TYPE_ORDER = { } # ============================================================================= -class PdnsApiRrsetError(PpBaseObjectError): +class PdnsApiRrsetError(FbBaseObjectError): pass @@ -85,7 +84,7 @@ def compare_rrsets(x, y): return 0 # ============================================================================= -class PdnsApiRecord(PpBaseObject): +class PdnsApiRecord(FbBaseObject): # ------------------------------------------------------------------------- def __init__( @@ -173,7 +172,7 @@ class PdnsApiRecord(PpBaseObject): # ============================================================================= -class PdnsSoaData(PpBaseObject): +class PdnsSoaData(FbBaseObject): re_soa_data = re.compile(r'^\s*(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$') re_ws = re.compile(r'\s+') @@ -392,7 +391,7 @@ class PdnsSoaData(PpBaseObject): return True # ============================================================================= -class PdnsApiRrset(PpBaseObject): +class PdnsApiRrset(FbBaseObject): default_ttl = 3600 diff --git a/lib/pp_lib/pdns_zone.py b/lib/pp_lib/pdns_zone.py index 3188d1b..b8ea11c 100644 --- a/lib/pp_lib/pdns_zone.py +++ b/lib/pp_lib/pdns_zone.py @@ -3,7 +3,7 @@ """ @author: Frank Brehm @contact: frank.brehm@pixelpark.com -@copyright: © 2018 by Frank Brehm, Publicies Pixelpark GmbH, Berlin +@copyright: © 2021 by Frank Brehm, Publicies Pixelpark GmbH, Berlin @summary: An encapsulation class for zone objects by PowerDNS API """ from __future__ import absolute_import @@ -17,23 +17,23 @@ import datetime from dns.resolver import Resolver, NoAnswer # Own modules -from .common import pp, to_utf8, to_bool -from .common import RE_DOT_AT_END +from fb_tools.common import pp, to_utf8, to_bool +from fb_tools.common import RE_DOT_AT_END +from fb_tools.obj import FbBaseObjectError, FbGenericBaseObject, FbBaseObject -from .obj import PpBaseObjectError, PpBaseObject from .pdns_record import PdnsApiRrset, PdnsSoaData -__version__ = '0.5.6' +__version__ = '0.5.7' LOG = logging.getLogger(__name__) # ============================================================================= -class PdnsApiZoneError(PpBaseObjectError): +class PdnsApiZoneError(FbBaseObjectError): pass # ============================================================================= -class PdnsApiZone(PpBaseObject): +class PdnsApiZone(FbBaseObject): # ------------------------------------------------------------------------- def __init__( @@ -308,7 +308,7 @@ class PdnsApiZone(PpBaseObject): res['api_rectify'] = self.api_rectify for rrset in self.rrsets: - if isinstance(rrset, PpBaseObject): + if isinstance(rrset, FbGenericBaseObject): res['rrsets'].append(rrset.as_dict(short)) else: res['rrsets'].append(rrset) diff --git a/lib/pp_lib/pidfile.py b/lib/pp_lib/pidfile.py index b938c2a..f91ad4d 100644 --- a/lib/pp_lib/pidfile.py +++ b/lib/pp_lib/pidfile.py @@ -24,20 +24,16 @@ import six from six import reraise # Own modules +from fb_tools.errors import ReadTimeoutError +from fb_tools.common import to_utf8 +from fb_tools.obj import FbBaseObjectError, FbBaseObject -from .errors import ReadTimeoutError - -from .obj import PpBaseObjectError -from .obj import PpBaseObject - -from .common import to_utf8 - -__version__ = '0.2.5' +__version__ = '0.2.6' LOG = logging.getLogger(__name__) # ============================================================================= -class PidFileError(PpBaseObjectError): +class PidFileError(FbBaseObjectError): """Base error class for all exceptions happened during handling a pidfile.""" @@ -106,7 +102,7 @@ class PidFileInUseError(PidFileError): # ============================================================================= -class PidFile(PpBaseObject): +class PidFile(FbBaseObject): """ Base class for a pidfile object. """