#! /usr/bin/python from cdb import cdbmake from sre import sub as r_sub, compile as r_compile from sys import argv, stderr, exit ego = r_sub(r'^.*[/\\]', '', argv[0]) def die(msg, tag = True): if tag: msg = '%s: %s' % (ego, msg) print >>stderr, msg exit(1) if len(argv) != 2: die('usage: %s GROUPFILE' % ego) rx_comment = r_compile(r'^\s*(\#|$)') group = argv[1] cdb = cdbmake(group + '.cdb', group + '.cdb.new') i = 0 for line in open(group, 'r'): i += 1 if rx_comment.match(line): continue f = line.split() if len(f) != 3: die('bad info line %d.' % i) l = ' '.join(f) tag, group, addr = f group = group.replace('.', '-') cdb.add('t:%s' % tag, l) cdb.add('g:%s' % group, l) cdb.finish()