--- a/bin/pvl.hosts-forward Wed Feb 25 15:49:11 2015 +0200
+++ b/bin/pvl.hosts-forward Wed Feb 25 15:55:23 2015 +0200
@@ -1,6 +1,40 @@
#!/usr/bin/env python
+import logging; log = logging.getLogger('pvl.hosts-forward')
+import optparse
+import pvl.args
+import pvl.hosts
import pvl.hosts.zone
-import sys
-sys.exit(pvl.hosts.zone.forward_main())
+def main (argv):
+ """
+ Generate bind zonefiles from host definitions.
+ """
+
+ parser = optparse.OptionParser(main.__doc__)
+ parser.add_option_group(pvl.args.parser(parser))
+ parser.add_option_group(pvl.hosts.config.optparser(parser))
+
+ parser.add_option('--forward-zone', metavar='DOMAIN',
+ help="Generate forward zone for domain")
+
+ parser.add_option('--add-origin', action='store_true',
+ help="Include $ORIGIN directive in zone")
+
+ # input
+ options, args = pvl.args.parse(parser, argv)
+
+ if not options.forward_zone:
+ log.fatal("required --forward-zone")
+ return 1
+
+ hosts = pvl.hosts.apply(options, args)
+
+ # process
+ for rr in pvl.hosts.zone.apply_hosts_forward(options, hosts, options.forward_zone):
+ print unicode(rr)
+
+ return 0
+
+if __name__ == '__main__':
+ pvl.args.main(main)
--- a/bin/pvl.hosts-reverse Wed Feb 25 15:49:11 2015 +0200
+++ b/bin/pvl.hosts-reverse Wed Feb 25 15:55:23 2015 +0200
@@ -1,6 +1,42 @@
#!/usr/bin/env python
+import logging; log = logging.getLogger('pvl.hosts-reverse')
+import optparse
+import pvl.args
+import pvl.hosts
import pvl.hosts.zone
-import sys
-sys.exit(pvl.hosts.zone.reverse_main())
+def main (argv):
+ """
+ Generate bind zonefiles from host definitions.
+ """
+
+ parser = optparse.OptionParser(main.__doc__)
+ parser.add_option_group(pvl.args.parser(parser))
+ parser.add_option_group(pvl.hosts.config.optparser(parser))
+
+ parser.add_option('--reverse-zone', metavar='PREFIX',
+ help="Generate reverse zone for prefix")
+
+ parser.add_option('--unknown-host', metavar='NAME',
+ help="Generate records for unused IPs")
+
+ # input
+ options, args = pvl.args.parse(parser, argv)
+
+ if not options.reverse_zone:
+ log.fatal("required --reverse-zone")
+ return 1
+
+ hosts = pvl.hosts.apply(options, args)
+
+ # process
+ prefix = pvl.dns.parse_prefix(options.reverse_zone)
+
+ for rr in pvl.hosts.zone.apply_hosts_reverse(options, hosts, prefix):
+ print unicode(rr)
+
+ return 0
+
+if __name__ == '__main__':
+ pvl.args.main(main)
--- a/pvl/hosts/zone.py Wed Feb 25 15:49:11 2015 +0200
+++ b/pvl/hosts/zone.py Wed Feb 25 15:55:23 2015 +0200
@@ -216,63 +216,3 @@
else:
continue
-import pvl.args
-import pvl.hosts.config
-
-import optparse
-
-def forward_main () :
- """
- Generate bind zonefiles from host definitions.
- """
-
- parser = optparse.OptionParser(forward_main.__doc__)
- parser.add_option_group(pvl.args.parser(parser))
- parser.add_option_group(pvl.hosts.config.optparser(parser))
-
- parser.add_option('--add-origin', action='store_true',
- help="Include $ORIGIN directive in zone")
-
- parser.add_option('--forward-zone', metavar='DOMAIN',
- help="Generate forward zone for domain")
-
- # input
- options, args = parser.parse_args()
-
- pvl.args.apply(options)
-
- hosts = pvl.hosts.apply(options, args)
-
- # process
- for rr in apply_hosts_forward(options, hosts, options.forward_zone):
- print unicode(rr)
-
- return 0
-
-def reverse_main () :
- """
- Generate bind zonefiles from host definitions.
- """
-
- parser = optparse.OptionParser(reverse_main.__doc__)
- parser.add_option_group(pvl.args.parser(parser))
- parser.add_option_group(pvl.hosts.config.optparser(parser))
-
- parser.add_option('--reverse-zone', metavar='PREFIX',
- help="Generate reverse zone for prefix")
-
- parser.add_option('--unknown-host', metavar='NAME',
- help="Generate records for unused IPs")
-
- # input
- options, args = parser.parse_args()
-
- pvl.args.apply(options)
-
- hosts = pvl.hosts.apply(options, args)
-
- # process
- for rr in apply_hosts_reverse(options, hosts, pvl.dns.parse_prefix(options.reverse_zone)):
- print unicode(rr)
-
- return 0