mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 19:52:54 +01:00
32 lines
637 B
Python
32 lines
637 B
Python
|
#!/usr/bin/env python
|
||
|
|
||
|
"""
|
||
|
Converts from a "key => value\n" format to a cdb database.
|
||
|
"""
|
||
|
|
||
|
import sys
|
||
|
sys.path.insert(0, 'src')
|
||
|
import re
|
||
|
|
||
|
import cdb
|
||
|
|
||
|
r = re.compile(r'(.*)\s+=>\s+(.*)\n')
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
if len(sys.argv) < 2:
|
||
|
print 'Usage: %s <dbname> (reads stdin for data)' % sys.argv[0]
|
||
|
sys.exit(-1)
|
||
|
maker = cdb.Maker(sys.argv[1])
|
||
|
lineno = 1
|
||
|
for line in sys.stdin:
|
||
|
m = r.match(line)
|
||
|
if m:
|
||
|
(key, value) = m.groups()
|
||
|
maker.add(key, value)
|
||
|
lineno += 1
|
||
|
else:
|
||
|
print 'Invalid Syntax, line %s' % lineno
|
||
|
maker.finish()
|
||
|
|
||
|
|