bin/pvl.hosts-forward
changeset 475 a76571e27c6f
parent 458 600ad9eb6f25
child 487 920394061b6f
--- 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)