return a data stream of the files compressed in zip format. Returns None if the list is empty.
(self)
| 459 | return False |
| 460 | |
| 461 | def zip(self): |
| 462 | """ |
| 463 | return a data stream of the files compressed in zip format. |
| 464 | Returns None if the list is empty. |
| 465 | """ |
| 466 | import cStringIO, zipfile |
| 467 | fobj = cStringIO.StringIO() |
| 468 | # make sure the list contains something |
| 469 | if len(self) >= 0: |
| 470 | try: |
| 471 | zip = zipfile.ZipFile(fobj, "w", zipfile.ZIP_DEFLATED) |
| 472 | except: |
| 473 | sys.stderr.write("Unable to open zip file.") |
| 474 | raise |
| 475 | try: |
| 476 | for name in self: |
| 477 | # only add files |
| 478 | if os.path.isfile(name): |
| 479 | zip.write(name) |
| 480 | zip.close() |
| 481 | return fobj.getvalue() |
| 482 | finally: |
| 483 | fobj.close() |
| 484 | else: |
| 485 | # return None if the list is empty. |
| 486 | return None |
| 487 | |
| 488 | if COMPAT23: |
| 489 | def targz(self): |
no test coverage detected