Commit | Line | Data |
---|---|---|
b2ffb9b7 | 1 | #! @PYTHON@ |
bba986ae MW |
2 | |
3 | from cdb import cdbmake | |
4 | from sre import sub as r_sub | |
5 | from sys import argv, stdin, stderr, exit | |
6 | ||
7 | ego = r_sub(r'^.*[/\\]', '', argv[0]) | |
8 | def die(msg, prefix = True): | |
841e5aca | 9 | if prefix: msg ='%s: %s' % (ego, msg) |
bba986ae MW |
10 | print >>stderr, msg |
11 | exit(1) | |
12 | ||
13 | def files(args): | |
14 | if len(args) == 0: | |
15 | yield stdin | |
16 | else: | |
17 | for a in args: | |
18 | if a == '-': | |
841e5aca | 19 | yield stdin |
bba986ae | 20 | else: |
841e5aca | 21 | yield open(a, 'r') |
bba986ae MW |
22 | |
23 | if len(argv) < 2: | |
24 | die('usage: %s CDB [INPUT ...]' % ego, False) | |
25 | ||
26 | cdb = cdbmake(argv[1], argv[1] + '.new') | |
27 | for f in files(argv[2:]): | |
28 | for line in f: | |
29 | if len(line) and line[-1] == '\n': line = line[:-1] | |
30 | k, v = line.split(':', 1) | |
31 | cdb.add(k, v) | |
32 | cdb.finish() |