# Own modules
-__version__ = '0.5.1'
+__version__ = '0.5.2'
LOG = logging.getLogger(__name__)
RE_DOT = re.compile(r'\.')
RE_DOT_AT_END = re.compile(r'(\.)*$')
+RE_DECIMAL = re.compile(r'^\d+$')
+RE_IPV4_PTR = re.compile(r'\.in-addr\.arpa\.$', re.IGNORECASE)
+RE_IPV6_PTR = re.compile(r'\.ip6\.arpa\.$', re.IGNORECASE)
# =============================================================================
# =============================================================================
def compare_fqdn(x, y):
+ #LOG.debug("Comparing {!r} <=> {!r}.".format(x, y))
+
# First check for None values
if x is None and y is None:
return 0
if xs == ys:
return 0
+ if RE_IPV4_PTR.search(xs):
+ if not RE_IPV4_PTR.search(ys):
+ return -1
+ elif RE_IPV4_PTR.search(ys):
+ if not RE_IPV4_PTR.search(xs):
+ return 1
+ elif RE_IPV6_PTR.search(xs):
+ if not RE_IPV6_PTR.search(ys):
+ return -1
+ elif RE_IPV6_PTR.search(ys):
+ if not RE_IPV6_PTR.search(xs):
+ return 1
+
xa = RE_DOT.split(xs)
xa.reverse()
xa.pop(0)
while nr_tokens > 0:
token_x = xa.pop(0)
token_y = ya.pop(0)
- if token_x < token_y:
- return -1
- elif token_x > token_y:
- return 1
+ if RE_DECIMAL.match(token_x) and RE_DECIMAL.match(token_y):
+ num_x = int(token_x)
+ num_y = int(token_y)
+ if num_x < num_y:
+ return -1
+ elif num_x > num_y:
+ return 1
+ else:
+ if token_x < token_y:
+ return -1
+ elif token_x > token_y:
+ return 1
nr_tokens -= 1
if len(xa):
import logging.config
import textwrap
+from functools import cmp_to_key
+
# Own modules
-from .common import pp
+from .common import pp, compare_fqdn
from .pdns_app import PpPDNSAppError, PpPDNSApplication
from .pdns_zone import PdnsApiZone
-__version__ = '0.2.1'
+__version__ = '0.2.2'
LOG = logging.getLogger(__name__)
print(line)
print('-' * len(line))
- for zone in zone_list:
+ for zone in sorted(zone_list, key=lambda x: cmp_to_key(compare_fqdn)(x.name)):
print(zone.get_line(len_zone))
# =============================================================================
('aa.de.', 'a.de.', 1),
('a.a.de.', 'a.de.', 1),
('a.de.', 'b.de', -1),
+ ('10.in-addr.arpa.', 'a.ai.', -1),
+ ('10.in-addr.arpa.', 'a.az.', -1),
+ ('10.in-addr.arpa.', 'f.ip6.arpa.', -1),
+ ('10.in-addr.arpa.', '11.in-addr.arpa.', -1),
+ ('200.in-addr.arpa.', '10.in-addr.arpa.', 1),
+ ('100.in-addr.arpa.', '11.in-addr.arpa.', 1),
+ ('f.ip6.arpa.', 'a.ai.', -1),
+ ('f.ip6.arpa.', 'a.az.', -1),
+ ('pixelpark.ag.', '1.1.10.in-addr.arpa.', 1),
)
for case in testcases: