]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Collecting zones to show
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 8 Nov 2017 12:46:00 +0000 (13:46 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 8 Nov 2017 12:46:00 +0000 (13:46 +0100)
pp_lib/pdns_show_zone.py

index 6a06fccddfc630d5216883d1c078b37781ff6e40..5e65022a73011ff6eeb94159c79319d1edc4b959 100644 (file)
@@ -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))