Re: [Zope-dev] Question about import code

2001-05-11 Thread Dieter Maurer

Shane Hathaway writes:
  Fred Wilson Horch wrote:
Importing multiple objects simultaneously could result in a fair amount
of confusion...
   
   Can you elaborate?  When you import a folder, for example, it imports
   the folder and all objects in it.
  
  If there are some objects in the folder that have conflicting names and
  others that don't, what do you do?
Zope already solves this problem for paste.
Although, I am not sure that I like this solution,
import should behave the same, for consistency.

  Also, if you're thinking about
  providing this functionality, what about spanning multiple folders? What
  if some folders already exist?
Again, it should behave like paste, for consistency.



Dieter

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Question about import code

2001-05-10 Thread Shane Hathaway

Fred Wilson Horch wrote:
 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.

Importing multiple objects simultaneously could result in a fair amount
of confusion...

But if you really think it's a good idea, if you used a list called
return_oids instead, and appended to this list in the code above, you'd
probably get what you're looking for.

ooid=h[:8]
if oids and oids.has_key(ooid):
oid=oids[ooid]
if type(oid) is TupleType: oid=oid[0]
else:
oids[ooid] = oid = new_oid()
return_oids.append(oid)

Then at the end of the function you'll want to dereference each of the
OIDs and return a list of objects.  Everything that uses import will
have to be modified, unless you change the name of the method and
provide a wrapper method with the existing signature.

Note that for Zope 2.4 this code has changed a bit.  Import is now done
as a subtransaction rather than a transaction on the side.

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Question about import code

2001-05-10 Thread Fred Wilson Horch

Hi Shane,

You wrote:
 
 Importing multiple objects simultaneously could result in a fair amount
 of confusion...

Can you elaborate?  When you import a folder, for example, it imports
the folder and all objects in it.

Why is it any different to import two unrelated objects?

Would it be better to do this in two separate transactions?  Or two
subtransactions?

 But if you really think it's a good idea, if you used a list called
 return_oids instead, and appended to this list in the code above, you'd
 probably get what you're looking for.

I tried this approach, too, and I get a ConflictError.  (I can send the
code and traceback if you're interested.)

 Note that for Zope 2.4 this code has changed a bit.  Import is now done
 as a subtransaction rather than a transaction on the side.

Thanks for the heads up.  When you say subtransaction, a
subtransaction of what?  I'm familiar with subtransactions being atomic
parts of a larger transaction.  I'm not sure what this larger
transaction would be in this case.  If I start an import, does that
start a transaction with each object's import being a subtransaction of
the whole thing?  (If that's the case, then I don't understand why
importing several objects at once would be confusing.)

Is there any documentation on how to export from and import to the ZODB?

The code I'm wading through has a lot of extraneous stuff thrown in. 
I'd like to be able to just try exporting and importing objects from a
simple Python script so I understand what's going on.

Thanks,
Fred
-- 
Fred Wilson Horch   mailto:[EMAIL PROTECTED]
Executive Director, EcoAccess   http://ecoaccess.org/
P.O. Box 2823, Durham, NC 27715-2823phone: 919.419-8567

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Question about import code

2001-05-10 Thread Shane Hathaway

Fred Wilson Horch wrote:
 You wrote:
 
  Importing multiple objects simultaneously could result in a fair amount
  of confusion...
 
 Can you elaborate?  When you import a folder, for example, it imports
 the folder and all objects in it.

If there are some objects in the folder that have conflicting names and
others that don't, what do you do?  Also, if you're thinking about
providing this functionality, what about spanning multiple folders? What
if some folders already exist?

The capability could change user expectations, you see, and you may need
to deal with them.  But that's just advice and you can freely ignore it.
:-)

 Thanks for the heads up.  When you say subtransaction, a
 subtransaction of what?  I'm familiar with subtransactions being atomic
 parts of a larger transaction.  I'm not sure what this larger
 transaction would be in this case.  If I start an import, does that
 start a transaction with each object's import being a subtransaction of
 the whole thing?

That's right.

 Is there any documentation on how to export from and import to the ZODB?

Perhaps.  Look at the interfaces Wiki.

 The code I'm wading through has a lot of extraneous stuff thrown in.
 I'd like to be able to just try exporting and importing objects from a
 simple Python script so I understand what's going on.

An external method could do it.  Look at what _getCopy() does in
OFS/CopySupport.py.

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )