[Zope] Zip za Zope (CMF or Plone folder objects)
Tino Wildenhain
tino at wildenhain.de
Fri Dec 3 04:09:49 EST 2004
Hi,
On Thu, 2004-12-02 at 21:30 -0400, David Pratt wrote:
> Hi. I would like to zip folder content in a couple of different ways
> in CMF and Plone:
>
> 1) zip in place (zip file made inside folder)
> 2) zip on filesystem (for email with link to download on apache)
>
> I believe this is possible using an external method with the StringIO
> and zipfile modules. I can't really find anything other than
> references to the zipfile module. Has anyone got something like this
> working in CMF or Plone before I begin spending time on this?
>
> I guess the big thing for me is getting a handle on the files. My
> thinking is to make a python script to get the contents of the current
> folder (and put this in my skin along with changes for links in my
> folder view templates), make a dictionary so I have the object id and
> data for each object and pass it to the external method. Then create
You can have the external method do this, reducing complexity
(and perhaps memory footprint if you code carefully)
> an empty string file object using StringIO and build the content of the
> zip file by iterating over the object ids and data from the dictionary
> I passed. Once I get the content of the zip file together, the other
> thing is to write it into the folder I obtained the data from. I want
> to have another version that would write it into an apache directory
> and then send the user an email with a download link. Is this a
> reasonable way to go or is there something better?
I'd generate the zip files on the fly. Just an external method like
this:
import zipfile
def zipfolder(self,filename='download.zip'):
response=self.REQUEST.RESPONSE
response.setHeader('Content-Type','application/zip')
response.setHeader('Content-Disposition','attachment; filename=%
s' % filename)
zf=zipfile.ZipFile(response,'w',zipefile.ZIP_DEFLATED)
for name,obj in self.objectItems(['File','Image']):
zf.writestr(name,str(obj))
zf.close()
You can call this in the context of the folder where you stored
the files. Adjust the argument to objectItems accordingly if
you want to handle other object types too.
HTH
Tino
More information about the Zope
mailing list