[ZODB-Dev] Tool for exploring raw ZODB data
Jeff Sasmor
jsasmor@gte.net
Sat, 15 Feb 2003 20:12:38 -0500
Rereading my last reply and your example impels me to
make what I wrote a bit clearer - If I'm boring everyone
on this list please let me know and I'll take it off line.
Your ZODB app probably isn't heirarchically saving
things in the ZODB - no folder/subobject heirarchy. I
made a minor change in the printing code so that
if what's returned isn't a dict it will just print it
letting Python figure out the best way to print.
The root[] of the db is a Persistent Mapping. My code
doesn't assume anything about what it pulls out: it just
gets the raw info that was put in there. The code doesn't
change anything at all, it just unpickles it in a special way
so that objects aren't actually constructed.
What's there may look odd and may surprise you - I have had
the same reaction, which is why I thought other people might
find the code interesting. The stuff at the end of the module
is just a simple way to test the code out and isn't really significant.
Certainly if you retrieve something 'interesting' you will
have to have an understanding of the attributes internal to that
something in order to see what's in there.
When you drill down into an attribute that's a tuple
or something without a key:value relationship then this
simple UI of using an 'object path' is meaningless.
To go past this point you'd need to change the code
so it would understand your own data structure, if
you cared to do so.
For example, if you retrieve the object data for a Persistent Mapping
all you'll get is a dict with a key '_container', hence, if you
wanted to get something+aPersistentMapping and see what's in it
you'd have to ask for something+aPersistentMapping+_container
and you'd see the key/value pairs in that dictionary. I haven't played
around with extracting the data from a BTree, you'd have to access
its IOBucket attribute, I suppose.
For example, looking at a Catalog instance's 'data' attribute you see:
((('\x00\x00\x00\x00\x00\x00\x01M', ('BTrees._IOBTree', 'IOBucket')),
1218705741,
('\x00\x00\x00\x00\x00\x00\x01N', ('BTrees._IOBTree', 'IOBucket'))),
('\x00\x0 0\x00\x00\x00\x00\x01M', ('BTrees._IOBTree', 'IOBucket')))
But although certainly one could delve into this deeper to access the IOBucket
at OID '\x00\x00\x00\x00\x00\x00\x01M' the code I have won't do that as it
needs a key to specify which subobject out of this tuple of four subobjects
(three IOBuckets and an integer (?)) to access.
Anyway, again, sorry if I caused any confusion.
-------------------
Jeff Sasmor
jeff@sasmor.com