Is it possible to set a quota on a folder? I.e. the folder knows how much space is consumed by the objects it contains, and refuses to add objects after a certain point. Clearly the actual data storage may be larger, due to the space consumed for undos, but this would be the "packed" size of the folder's contents. Also, the packed size is something users can more easily manage for themselves. I need to set something like this up for site users to have a small amount of user space on the system (and avoid abuse of it). I was hoping there would be a product to do this, but I haven't found one, so perhaps I'll write one. But I'd prefer not to reinvent if not necessary. Also, any hints on how to do it would be appreciated. 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. Alternatively, maybe I could catch the size when the objects were added or deleted? Thanks for any ideas, Terry -- ------------------------------------------------------ Terry Hancock hancock@anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com ------------------------------------------------------
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 ------------------------------------------------------
participants (1)
-
Terry Hancock