[Zope] Re: Quotas on folder

Terry Hancock hancock@anansispaceworks.com
Tue, 12 Feb 2002 14:40:34 -0800


Sorry, I think I answered my own question --

I added a Python script:

#
size = 0
for obj in context.objectValues()
	size = size + obj.get_size()
return size

and called it "get_size"

This appears to work because the getSize/get_size discrepency
seems to have disappeared, at least in Zope 2.4.3, which is
what I'm using.  The only thing I tested for that didn't
have a "get_size()" method was folders, and putting the
above script in the top level folder makes it available to
subfolders. So calling myfolder.get_size() (or accessing
/myfolder/get_size ) returns a "du"-like result on the
folder tree.

I suppose this could crash or return odd results if some
object doesn't have a get_size(), but so far it works on
everything I've tested it on.  Probably I should add
a has_key() check on the object.

It appears also that I could've gotten the same results
if I changed "get_size" to "getSize" throughout the
example above. I wonder if one is deprecated?

If I actually add user objects through a proxy (like the
"guest book" example in The Zope Book), I should be able
to check the size before allowing the upload.

So I probably don't really need to create a product for
this, though I might incorporate it into another one.

Thanks,
Terry

Terry Hancock wrote:
> Currently it looks as if I would have to iterate the
> folders contents and call "getSize()" for Files and
> Images and "get_size()" for DTMLDocuments and DTMLMethods,
> and possibly something else for other content (presumeably
> I'd have to recursively search Folders, for example).
> This is basically the "du" (*nix command) approach.

-- 
------------------------------------------------------
Terry Hancock
hancock@anansispaceworks.com       
Anansi Spaceworks                 
http://www.anansispaceworks.com 
------------------------------------------------------