From: Frank Brehm Date: Fri, 4 May 2018 08:08:49 +0000 (+0200) Subject: Adding some arguments for a minimized output X-Git-Tag: 0.1.2~6^2~20^2~1 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=62dc7c2b58f2210b8896b6f60e94215bb6a5ea92;p=pixelpark%2Fadmin-tools.git Adding some arguments for a minimized output --- diff --git a/pp_lib/pdns_list_zones.py b/pp_lib/pdns_list_zones.py index ffcaca3..be91a52 100644 --- a/pp_lib/pdns_list_zones.py +++ b/pp_lib/pdns_list_zones.py @@ -21,7 +21,7 @@ from .common import compare_fqdn from .pdns_app import PpPDNSAppError, PpPDNSApplication from .pdns_zone import PdnsApiZone -__version__ = '0.4.1' +__version__ = '0.5.1' LOG = logging.getLogger(__name__) @@ -39,7 +39,10 @@ class PpPDNSListZonesApp(PpPDNSApplication): # ------------------------------------------------------------------------- def __init__(self, appname=None, version=__version__): + self.no_header = False + self.no_summary = False self.show_numbers = False + self.minimal = False description = textwrap.dedent('''\ Lists all available zones from given PowerDNS API. @@ -63,6 +66,25 @@ class PpPDNSListZonesApp(PpPDNSApplication): super(PpPDNSListZonesApp, self).init_arg_parser() self.arg_parser.add_argument( + '-H', '--no-header', action='store_true', dest='no_header', + help="Don't show header lines at the beginning of the list." + ) + + self.arg_parser.add_argument( + '-n', '--no-summary', action='store_true', dest='no_summary', + help="Don't show summary at the end of the list." + ) + + col_group = self.arg_parser.add_mutually_exclusive_group() + + col_group.add_argument( + '-M', '--minimal', action='store_true', dest='minimal', + help=( + "Minimal output, includes --no-header and --no-summary. " + "Mutually exclusive to --numbers.") + ) + + col_group.add_argument( '-N', '--numbers', action='store_true', dest='show_numbers', help="Show number of Ressource Record Sets and Records for each zone", ) @@ -76,9 +98,21 @@ class PpPDNSListZonesApp(PpPDNSApplication): super(PpPDNSListZonesApp, self).perform_arg_parser() + if self.args.no_header: + self.no_header = True + + if self.args.no_summary: + self.no_summary = True + if self.args.show_numbers: self.show_numbers = True + if self.args.minimal: + self.no_header = True + self.no_summary = True + self.minimal = True + self.show_numbers = False + # ------------------------------------------------------------------------- def _run(self): @@ -92,16 +126,23 @@ class PpPDNSListZonesApp(PpPDNSApplication): if len(zone.name_unicode) > len_zone: len_zone = len(zone.name_unicode) - if self.show_numbers: + if self.minimal: + tpl = PdnsApiZone.get_list_template(minimal=True) + elif self.show_numbers: tpl = PdnsApiZone.get_list_template(show_numbers=True) else: tpl = PdnsApiZone.get_list_template(show_numbers=False) - line = tpl.format( - name="Zone", len_zone=len_zone, kind="Type", serial="Serial", - dnssec="DNSSEC", nr_rrsets='RR Sets', nr_records='Records', - account="Account information") - print(line) - print('-' * len(line)) + + if self.verbose > 2: + LOG.debug("Used template for line: {!r}".format(tpl)) + + if not self.no_header: + line = tpl.format( + name="Zone", len_zone=len_zone, kind="Type", serial="Serial", + dnssec="DNSSEC", nr_rrsets='RR Sets', nr_records='Records', + account="Account information") + print(line) + print('-' * len(line)) nr_zones = 0 nr_rrsets = 0 @@ -116,13 +157,14 @@ class PpPDNSListZonesApp(PpPDNSApplication): nr_records += 1 print(zone.get_line(len_zone, zone_complete.rrsets)) else: - print(zone.get_line(len_zone)) - - print('-' * len(line)) - line = tpl.format( - name="Total:", len_zone=len_zone, kind="", serial=nr_zones, - dnssec="Zones", nr_rrsets=nr_rrsets, nr_records=nr_records, account="") - print(line) + print(zone.get_line(len_zone, minimal=self.minimal)) + + if not self.no_summary: + print('-' * len(line)) + line = tpl.format( + name="Total:", len_zone=len_zone, kind="", serial=nr_zones, + dnssec="Zones", nr_rrsets=nr_rrsets, nr_records=nr_records, account="") + print(line) # ============================================================================= diff --git a/pp_lib/pdns_zone.py b/pp_lib/pdns_zone.py index 64f8eeb..3188d1b 100644 --- a/pp_lib/pdns_zone.py +++ b/pp_lib/pdns_zone.py @@ -23,7 +23,7 @@ from .common import RE_DOT_AT_END from .obj import PpBaseObjectError, PpBaseObject from .pdns_record import PdnsApiRrset, PdnsSoaData -__version__ = '0.5.5' +__version__ = '0.5.6' LOG = logging.getLogger(__name__) @@ -348,7 +348,10 @@ class PdnsApiZone(PpBaseObject): # ------------------------------------------------------------------------- @classmethod - def get_list_template(cls, show_numbers=False): + def get_list_template(cls, show_numbers=False, minimal=False): + + if minimal: + return "{name}" tpl = "{name:<{len_zone}} {kind:<8} {serial:>10} {dnssec:<6}" if show_numbers: @@ -357,12 +360,14 @@ class PdnsApiZone(PpBaseObject): return tpl # ------------------------------------------------------------------------- - def get_line(self, len_zone=20, rrsets=None): + def get_line(self, len_zone=20, rrsets=None, minimal=False): - if rrsets: - tpl = self.get_list_template(True) + if minimal: + tpl = self.get_list_template(minimal=True) + elif rrsets: + tpl = self.get_list_template(show_numbers=True) else: - tpl = self.get_list_template(False) + tpl = self.get_list_template(show_numbers=False) params = { 'name': self.name_unicode,