1
0
mirror of https://github.com/oskar456/dzonegit.git synced 2024-05-11 05:55:41 +00:00

Refactor get_zone_origin()

This commit is contained in:
Ondřej Caletka
2018-07-06 22:35:08 +02:00
parent 96f06ac1a1
commit 241b888215
2 changed files with 6 additions and 12 deletions

View File

@@ -112,15 +112,15 @@ def get_altered_files(against, diff_filter=None):
return (Path(p) for p in r.stdout.rstrip("\0").split("\0"))
def get_zone_origin(zonedata, maxlines=10):
def get_zone_origin(zonedata):
"""
Parse $ORIGIN directive in first maxlines lines of zone file.
Parse $ORIGIN directive before the SOA record.
Return zone name without the trailing dot.
"""
for i, line in enumerate(zonedata.splitlines()):
if i >= maxlines:
for line in zonedata.splitlines():
if re.match(r"^[^\s;]+\s+([0-9]+\s+)?(IN\s+)?SOA\s+", line, re.I):
break
m = re.match(r"^\$ORIGIN\s+([^ ]+)\.\s*(;.*)?$", line)
m = re.match(r"^\$ORIGIN\s+([^ ]+)\.\s*(;.*)?$", line, re.I)
if m:
return m.group(1).lower()