#!/usr/bin/python # db2gdbm: converts DB to GDBM import sys import dbm, gdbm if len(sys.argv)<3: print "usage: db2gdbm infile outfile" sys.exit(1) (infile, outfile) = sys.argv[1:] # open the files try: db_in = dbm.open(infile) except: print "Can't open infile %s: %s!" % (infile, sys.exc_info()[1]) sys.exit(1) try: db_out = dbm.open(outfile,"n") except: print "Can't open outfile %s: %s!" % (outfile, sys.exc_info()[1]) sys.exit(1) # copy (don't use db_out = db_in because it's slow on big databases) # is this also so for python ? for k in db_in.keys(): db_out[k] = db_in[k] # these close happen automatically at program exit db_out.close() db_in.close()