[Zope] CMFBTreeFolder Behavior

Paul Winkler pw_lists at slinkp.com
Mon Feb 28 10:31:43 EST 2005


On Mon, Feb 28, 2005 at 10:07:48AM -0400, David Pratt wrote:
> Hi.  I am working with the CMFBTreeFolder for the first time. I thought 
> it would make sense since I am wanting to use this type for an uploads 
> folder.  There may be thousands of objects.  Once files have been 
> uploaded to the folder, I am running a script to pull out images using 
> a for statement like this:
> 
> 	# Iterate over folder contents
> 	for name, obj in start_dir.objectItems(['Portal Image']):
> 		
> and then executing some logic on the images afterwards.  I am planning 
> to cron the script unless I can figure a way to execute the logic as 
> files are coming into the folder (which would be the best - so any 
> ideas here would be great).
> 
> In any case, what happens is that about half the objects get processed 
> with each run of the script.  For example if I had 1030 objects about 
> half gets processed, and then half of that and so on.  I may take 4 
> runs to get everything processed in the folder.  On a normal Folder or 
> CMF Portal Folder, all objects get processed in one run.

I'm just guessing, but it may be that in CMFBtreeFolder,
objectItems() returns not a list but some kind of iterator
that lazily gets the next batch of images.  I don't know what
you're *doing* with those images you find, but if the result is
to change the result of what objectItems() would return, you
might be getting into undefined behavior territory.

Easy ways to find out would be 
1)  read the source of CMFBTreeFolder and maybe base classes.

2) try looping over list(start_dir.objectItems(['Portal Image'])
   instead and see if that just works.
   But maybe unacceptable performance 
   if the list is really really huge.

FWIW, I'd take a different approach (I think... hard to be
sure since I don't know what you want to DO with these images):
Use workflow.

DCWorkflow provides for "automatic" transitions, where
an object in one state can automatically transition to
another state whenever some guard condition is met.

So, write a script like "postprocessImage" that does what
you want to *one* Image, add it to your Images workflow as a script
in an automatic transition that always occurs from the workflow's
initial state.  The result is that this script will get called
on every image exactly once just after it's created.

There's a good doc on DCWorkflow somewhere, PDF I think.
Google should find it.
 
-- 

Paul Winkler
http://www.slinkp.com


More information about the Zope mailing list