def available_exports(self): """any zip files avail to download? """ proj_id = self.context.getId() zips = export_utils.getzips(proj_id, self.vardir) path = export_utils.getpath(proj_id, self.vardir) # don't want to pile up zip files forever... # in lieu of a UI or a sensible policy, # we'll just keep the last 5 zips, excess_zips = zips[:5], zips[5:] for f in excess_zips: os.unlink(os.path.join(path, f)) return zips
def __getitem__(self, name): """ Return a zip file. """ zips = self.available_exports() path = export_utils.getpath(self.context.getId(), self.vardir) try: index = zips.index(name) except ValueError: # want a 404 here. raise KeyError(name) thezip = os.path.join(path, zips[index]) self.request.RESPONSE.setHeader('Content-Type', 'application/zip') # Tell ZPublisher to serve this file efficiently, freeing up # the Zope thread immediately. iterator = FilestreamIterator(thezip) self.request.RESPONSE.setHeader('Content-Length', len(iterator)) # Needs to be aq-wrapped to satisfy the security machinery. return iterator.__of__(self)