from .pdns_app import PpPDNSAppError, PpPDNSApplication
from .pdns_zone import PdnsApiZone
-__version__ = '0.4.1'
+__version__ = '0.5.1'
LOG = logging.getLogger(__name__)
# -------------------------------------------------------------------------
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.
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",
)
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):
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
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)
# =============================================================================
from .obj import PpBaseObjectError, PpBaseObject
from .pdns_record import PdnsApiRrset, PdnsSoaData
-__version__ = '0.5.5'
+__version__ = '0.5.6'
LOG = logging.getLogger(__name__)
# -------------------------------------------------------------------------
@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:
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,