Converting old "shelve" databases to gdbm

R

RayOsborn

I have some old "shelve" databases created in Python 2.2 that use the
old bsddb format, whereas the version of Python 2.4 installed by my
web hosting service doesn't have bsddb available at all (or at least,
it has, but probably not linked properly to the more recent Sleepy Cat
versions of the Berkeley DB - it fails to import _bsddb). Currently,
I have to put python2.2 in my shebangs to get the cgi scripts to run
at all. The question is how to migrate the databases to a format
supported by my installation of Python when I don't have complete
control over how it's installed.

The databases are fairly small, so I don't need high performance. In
some ways, the simplest thing would be to write a script within
python2.2 to read in the old databases and write them out again using,
say, gdbm. However, I can't specify the database protocol in the old
2.2 version of shelve, and I can't use gdbm directly because it would
only accept strings as values, whereas I have Python objects.

Any tips welcome.
 
I

Istvan Albert

Any tips welcome.

pickling has a text protocol that should be compatible across python
versions. Pickle each of your database entries to a different file,
then read them in the newer version of the script.

i.
 
R

RayOsborn

pickling has a text protocol that should be compatible across python
versions. Pickle  each of your database entries to a different file,
then read them in the newer version of the script.

i.

Thanks for the suggestion. I had forgotten that pickle by default has
an ASCII format - I've now written a couple of scripts, first in
Python 2.2 and then in the current default version to do the
translation. A bit tedious, but it works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top