49 help="Write to output file; default stdout") |
49 help="Write to output file; default stdout") |
50 |
50 |
51 parser.add_option('--output-charset', metavar='CHARSET', default='utf-8', |
51 parser.add_option('--output-charset', metavar='CHARSET', default='utf-8', |
52 help="Encoding used for output files") |
52 help="Encoding used for output files") |
53 |
53 |
54 # read line mtimes? |
|
55 parser.add_option('--input-line-date', action='store_true', |
|
56 help="Parse timestamp prefix from each input line (e.g. `hg blame | ...`)") |
|
57 |
|
58 # check stage |
54 # check stage |
59 parser.add_option('--check-hosts', action='store_true', |
55 parser.add_option('--check-hosts', action='store_true', |
60 help="Check that host/IPs are unique. Use --quiet to silence warnings, and test exit status") |
56 help="Check that host/IPs are unique. Use --quiet to silence warnings, and test exit status") |
61 |
57 |
62 parser.add_option('--check-exempt', action='append', |
58 parser.add_option('--check-exempt', metavar='HOST', action='append', |
63 help="Allow given names to have multiple records") |
59 help="Allow given names to have multiple records") |
|
60 |
|
61 # meta stage |
|
62 parser.add_option('--meta-zone', action='store_true', |
|
63 help="Generate host metadata zone; requires --input-line-date") |
|
64 |
|
65 parser.add_option('--meta-ignore', metavar='HOST', action='append', |
|
66 help="Ignore given hostnames in metadata output") |
|
67 |
|
68 parser.add_option('--input-line-date', action='store_true', |
|
69 help="Parse timestamp prefix from each input line (e.g. `hg blame | ...`)") |
64 |
70 |
65 # forward stage |
71 # forward stage |
66 parser.add_option('--forward-zone', action='store_true', |
72 parser.add_option('--forward-zone', action='store_true', |
67 help="Generate forward zone") |
73 help="Generate forward zone") |
68 |
74 |
379 comment = r.line.comment |
385 comment = r.line.comment |
380 |
386 |
381 if comment : |
387 if comment : |
382 yield TXTRecord(None, comment, ttl=r.ttl) |
388 yield TXTRecord(None, comment, ttl=r.ttl) |
383 |
389 |
384 # timestamp? |
390 |
385 timestamp = r.line.timestamp |
|
386 |
|
387 if timestamp : |
|
388 yield TXTRecord(None, timestamp.strftime(TIMESTAMP_FORMAT), ttl=r.ttl) |
|
389 |
|
390 # XXX: RP, do we need it? |
391 # XXX: RP, do we need it? |
391 |
392 |
392 if mx : |
393 if mx : |
393 # XXX: is this a good idea? |
394 # XXX: is this a good idea? |
394 yield ZoneRecord(None, 'MX', [10, mx], ttl=r.ttl) |
395 yield ZoneRecord(None, 'MX', [10, mx], ttl=r.ttl) |
395 |
396 |
|
397 def process_zone_meta (zone, ignore=None) : |
|
398 """ |
|
399 Process zone metadata -> output. |
|
400 """ |
|
401 |
|
402 TIMESTAMP_FORMAT='%Y/%m/%d' |
|
403 |
|
404 for r in zone : |
|
405 if ignore and r.name in ignore : |
|
406 # skip |
|
407 log.debug("Ignore record: %s", r) |
|
408 continue |
|
409 |
|
410 # for hosts.. |
|
411 if r.type == 'A' : |
|
412 # timestamp? |
|
413 timestamp = r.line.timestamp |
|
414 |
|
415 if timestamp : |
|
416 yield TXTRecord(r.name, timestamp.strftime(TIMESTAMP_FORMAT), ttl=r.ttl) |
|
417 |
396 def reverse_addr (ip) : |
418 def reverse_addr (ip) : |
397 """ |
419 """ |
398 Return in-addr.arpa reverse for given IPv4 IP. |
420 Return in-addr.arpa reverse for given IPv4 IP. |
399 """ |
421 """ |
400 |
422 |
503 if options.forward_zone : |
525 if options.forward_zone : |
504 log.info("Write forward zone: %s", output) |
526 log.info("Write forward zone: %s", output) |
505 |
527 |
506 zone = list(process_zone_forwards(zone, txt=options.forward_txt, mx=options.forward_mx)) |
528 zone = list(process_zone_forwards(zone, txt=options.forward_txt, mx=options.forward_mx)) |
507 |
529 |
|
530 elif options.meta_zone : |
|
531 log.info("Write metadata zone: %s", output) |
|
532 |
|
533 if not options.input_line_date : |
|
534 log.error("--meta-zone requires --input-line-date") |
|
535 return 1 |
|
536 |
|
537 zone = list(process_zone_meta(zone, ignore=set(options.meta_ignore))) |
|
538 |
508 elif options.reverse_zone : |
539 elif options.reverse_zone : |
509 origin = reverse_addr(options.reverse_zone) |
540 origin = reverse_addr(options.reverse_zone) |
510 domain = options.reverse_domain |
541 domain = options.reverse_domain |
511 |
542 |
512 if not domain : |
543 if not domain : |