pvl.hosts-import: check_hosts: verify nonexistan aliases
authorTero Marttila <terom@paivola.fi>
Mon, 16 Dec 2013 21:15:25 +0200
changeset 288 2f2f92e4c58e
parent 287 968130f21270
child 289 b316deddf746
pvl.hosts-import: check_hosts: verify nonexistan aliases
bin/pvl.hosts-import
--- a/bin/pvl.hosts-import	Mon Dec 16 21:10:40 2013 +0200
+++ b/bin/pvl.hosts-import	Mon Dec 16 21:15:25 2013 +0200
@@ -421,7 +421,14 @@
     
     return hosts.iteritems()
 
-def process_export_hosts (options, hosts) :
+def check_hosts (options, hosts) :
+    by_name = dict(hosts)
+
+    for host, fields in hosts :
+        if set(fields) == set(['alias']) :
+            log.warn("%s: nonexistant alias target: %s", host, ' '.join(fields['alias']))
+
+def sort_export_hosts (options, hosts) :
     if options.output_prefix :
         prefix = ipaddr.IPNetwork(options.output_prefix)
     else :
@@ -454,7 +461,7 @@
     yield u"[{domain}]".format(domain=options.hosts_domain)
 
     # filter + sort
-    hosts = [(host, fields) for sort, host, fields in sorted(process_export_hosts(options, hosts))]
+    hosts = [(host, fields) for sort, host, fields in sorted(sort_export_hosts(options, hosts))]
 
     for host, fields in hosts :
         for comment in fields.get('comment-host', ()):
@@ -509,8 +516,11 @@
         hosts = pvl.args.apply_files(args, 'r', options.input_charset)
     else :
         # import
-        hosts = import_hosts(options)
+        hosts = list(import_hosts(options))
    
+    # verify
+    check_hosts(options, hosts)
+
     # output
     if options.output_hosts :
         apply_hosts_export(options, hosts)