chiark / gitweb /
mtimeout.c: Accept time unit specification on timeout options.
[misc] / cdb-map.in
... / ...
CommitLineData
1#! @PYTHON@
2### -*-python-*-
3
4from cdb import cdbmake
5from re import sub as r_sub
6from sys import argv, stdin, stderr, exit
7
8ego = r_sub(r'^.*[/\\]', '', argv[0])
9def die(msg, prefix = True):
10 if prefix: msg ='%s: %s' % (ego, msg)
11 print >>stderr, msg
12 exit(1)
13
14def files(args):
15 if len(args) == 0:
16 yield stdin
17 else:
18 for a in args:
19 if a == '-':
20 yield stdin
21 else:
22 yield open(a, 'r')
23
24if len(argv) < 2:
25 die('usage: %s CDB [INPUT ...]' % ego, False)
26
27cdb = cdbmake(argv[1], argv[1] + '.new')
28for f in files(argv[2:]):
29 for line in f:
30 if len(line) and line[-1] == '\n': line = line[:-1]
31 k, v = line.split(':', 1)
32 cdb.add(k, v)
33cdb.finish()