From f56d7124bf13edd6a8d143ddd489c0568a9c2521 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Thu, 2 Mar 2006 02:02:42 +0000 Subject: [PATCH] cdb: General drive to eliminate freecdb and libfile-cdb-perl. Organization: Straylight/Edgeware From: Mark Wooding --- README | 2 +- bin/mail | 2 +- bin/mkcdb | 45 +++++++++++++++++++++++++++------------------ bin/mkgroups | 2 +- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/README b/README index 6ceec51..86db1b7 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ REQUIRED STUFF INN 2 qmail 1.03 - splitconf, tinycdb, libfile-cdb-perl (CDB_File.pm) + splitconf, tinycdb, python-cdb INITIAL INSTALLATION diff --git a/bin/mail b/bin/mail index 20b2d66..6ef138d 100755 --- a/bin/mail +++ b/bin/mail @@ -5,7 +5,7 @@ set -e [ $# = 1 ] || fail "usage: $0 GROUP" group=$1 -entry=`cdbget "g:$group" new("$g.cdb", "$g.new") or die "$0: cdbmake($g.cdb): $!\n"; -while () { - next if m'^\s*(\#|$)'; - my @f = split; - @f == 3 or die "$0: bad info line $.\n"; - my $l = join(" ", @f); - my ($tag, $group, $addr) = @f; - $group =~ tr/./-/; - $c->insert("t:$tag" => $l); - $c->insert("g:$group" => $l); -} -$c->finish() or die "$0: cdbfinish($g.cdb): $!\n"; -exit 0; +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() diff --git a/bin/mkgroups b/bin/mkgroups index 49b79ff..1cce11a 100755 --- a/bin/mkgroups +++ b/bin/mkgroups @@ -11,4 +11,4 @@ while read tag group addr; do else run ctlinnd newgroup mail.$group m newsgate fi -done \ No newline at end of file +done -- [mdw]