From: Frank Brehm Date: Wed, 8 Nov 2017 12:46:00 +0000 (+0100) Subject: Collecting zones to show X-Git-Tag: 0.1.2~106 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=52523aad7e0cfe0b51787e3d1f51c3f026ead295;p=pixelpark%2Fadmin-tools.git Collecting zones to show --- diff --git a/pp_lib/pdns_show_zone.py b/pp_lib/pdns_show_zone.py index 6a06fcc..5e65022 100644 --- a/pp_lib/pdns_show_zone.py +++ b/pp_lib/pdns_show_zone.py @@ -17,12 +17,13 @@ import textwrap from functools import cmp_to_key # Own modules -from .common import pp, compare_fqdn +from .common import pp, compare_fqdn, to_str +from .common import RE_DOT_AT_END from .pdns_app import PpPDNSAppError, PpPDNSApplication from .pdns_zone import PdnsApiZone -__version__ = '0.1.0' +__version__ = '0.2.0' LOG = logging.getLogger(__name__) @@ -40,7 +41,7 @@ class PpPDNSShowZoneApp(PpPDNSApplication): # ------------------------------------------------------------------------- def __init__(self, appname=None, version=__version__): - self.zone = None + self.zones = [] description = textwrap.dedent('''\ Lists all available zones from given PowerDNS API. @@ -52,11 +53,51 @@ class PpPDNSShowZoneApp(PpPDNSApplication): self.initialized = True + # ------------------------------------------------------------------------- + def init_arg_parser(self): + """ + Method to initiate the argument parser. + + This method should be explicitely called by all init_arg_parser() + methods in descendant classes. + """ + + super(PpPDNSShowZoneApp, self).init_arg_parser() + + self.arg_parser.add_argument( + 'zones', metavar='ZONE', nargs='+', + help="All zones, for which the complete information should shown", + ) + + # ------------------------------------------------------------------------- + def perform_arg_parser(self): + """ + Public available method to execute some actions after parsing + the command line parameters. + """ + + super(PpPDNSShowZoneApp, self).perform_arg_parser() + + for zone in self.args.zones: + zone_idna = zone + if 'xn--' not in zone: + zone_idna = to_str(zone.encode('idna')) + zone_idna = RE_DOT_AT_END.sub('.', zone_idna) + self.zones.append(zone_idna) + # ------------------------------------------------------------------------- def _run(self): - LOG.info("Show all information about zone {!r} from PowerDNS environment {!r}.".format( - self.zone, self.environment)) + for zone in self.zones: + + zone_unicode = zone + zout = "{!r}".format(zone) + if 'xn--' in zone: + zone_unicode = zone.encode('idna').decode('idna') + zout = "{!r} ({})".format(zone, zone_unicode) + + LOG.info("Show all information about zone {} from PowerDNS environment {!r}.".format( + zout, self.environment))