# HG changeset patch # User Tero Marttila # Date 1387221325 -7200 # Node ID 2f2f92e4c58e1186b01289c4048eb72b09105281 # Parent 968130f2127016f499dc86ab3d44e02d6adee230 pvl.hosts-import: check_hosts: verify nonexistan aliases diff -r 968130f21270 -r 2f2f92e4c58e 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)