[Zope-dev] Question about import code

Fred Wilson Horch fhorch@ecoaccess.org
Sat, 05 May 2001 23:08:43 -0400


Hi folks,

I have hacked on the export code to allow you to export more than one
object at a time.  Now I'm trying to grok the import code.  Can someone
help me figure out what's going on?

I have an export file in XML format that looks like this:

<?xml version="1.0"?>
<ZopeData>
  <record id="5602" aka="AAAAAAAAFeI=">
    [ first record's data here... ]
  </record>
  <record id="5603" aka="AAAAAAAAFeM=">
     [ second record's data here... ]
  </record>
</ZopeData>

If you export a folderish object, you'll see basically the same export
format.  (When you export a folder, you get all of the objects rooted in
that folder.)  The difference is that these two records are not related
-- they are simply both contained in the same folder.

The problem that happens on import is a KeyError on line 194 of this bit
of code:

lines 192-197 of lib/python/ZODB/ExportImport.py

                ooid=h[:8]
                if oids:
                    oid=oids[ooid]
                    if type(oid) is TupleType: oid=oid[0]
                else:
                    oids[ooid]=return_oid=oid=new_oid()

If I change this code to

                ooid=h[:8]
                if oids and oids.has_key(ooid):
                    oid=oids[ooid]
                    if type(oid) is TupleType: oid=oid[0]
                else:
                    oids[ooid]=return_oid=oid=new_oid()
                
then the import appears to succeed, but only the final object in the
file is actually imported.

I have to say that some comments would be nice in
lib/python/ZODB/ExportImport.py

Also, are both of these files used?

lib/python/ExportImportXML.py
lib/python/OFS/XMLExportImport.py

Plus, I am having a hard time finding the right documentation for
working directly with the ZODB to see what's going on.

Can someone help point me in the right direction?

Here's what I'm trying to accomplish:

1.  Allow multiple objects to be exported at once (this is working)
2.  Allow multiple objects to be imported at once (this is not)
3.  Allow imports to overwrite existing objects (haven't tried this yet)

Thanks in advance for any assistance.

Fred
-- 
Fred Wilson Horch			mailto:fhorch@ecoaccess.org
Executive Director, EcoAccess		http://ecoaccess.org/
P.O. Box 2823, Durham, NC 27715-2823	phone: 919.419-8567