Database conversion help - db2pickle.py and pickle2db.py
Skip Montanaro
skip at pobox.com
Mon Feb 3 11:00:19 EST 2003
I just checked in two scripts to the Python Tools/scripts CVS directory,
db2pickle.py and pickle2db.py. They should help people upgrade from older
versions of various database modules when Python is updated. Here's a
simple example of how they are used:
% python2.2 db2pickle.py some.db some.pickle
% python2.3 pickle2db.py some.db.new some.pickle
The first walks the bsddb hash database in some.db and writes out pickled
key/value tuples to some.pickle. The second reads pickled key/value tuples
from some.pickle and writes them out to the bsddb hash database some.db.new.
Something like this will be the most common usage I suspect. A validator
script isn't really possible, since in the general case, some.db and
some.db.new won't both be readable in the same Python interpreter.
The following five database formats are supported:
bsddb hash
bsddb btree
bsddb recno
anydbm
dbm
The default is bsddb hash. I didn't bother with the dbhash wrapper because
dbhash.open is just bsddb.hashopen. Dumbdbm didn't seem worth it, either.
In any case, I don't believe its format has changed since it was first
written.
I've tested the scripts to a reasonable degree using the bsddb hash and
bsddb btree formats with Python 2.1.3, 2.2.2 and current CVS (2.3a1+). I've
also attempted to avoid any gratuitous incompatibilities with earlier
versions, however I would appreciate it if people with 1.5.2 and 2.0 and/or
who use different database formats would test them a bit. If you don't have
a CVS version of the Python distribution handy, you can grab the scripts
individually from SourceForge:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Tools/scripts/
Feedback is welcome.
Skip
More information about the Python-list
mailing list