return a data stream of the files in gzipped tar format. Returns None if the list is empty.
(self)
| 487 | |
| 488 | if COMPAT23: |
| 489 | def targz(self): |
| 490 | """ |
| 491 | return a data stream of the files in gzipped tar format. |
| 492 | Returns None if the list is empty. |
| 493 | """ |
| 494 | import tarfile, cStringIO |
| 495 | # Create file in memory. I use cStringIO for speed. |
| 496 | fobj = cStringIO.StringIO() |
| 497 | # if the list contains anything |
| 498 | if len(self) >= 0: |
| 499 | # create the tarfile using the cStringIO buffer |
| 500 | try: |
| 501 | tar = tarfile.open('', "w:gz", fobj) |
| 502 | except: |
| 503 | sys.stderr.write("Unable to open tar.gz file.") |
| 504 | raise |
| 505 | try: |
| 506 | for name in self: |
| 507 | # only add files |
| 508 | if os.path.isfile(name): |
| 509 | try: |
| 510 | tar.add(name) |
| 511 | except ValueError: |
| 512 | # it can't store extremely long names |
| 513 | # so tell which ones and continue |
| 514 | sys.stderr.write('Warning: Unable to store: ') |
| 515 | sys.stderr.write(name) |
| 516 | sys.stderr.write('\n') |
| 517 | tar.close() |
| 518 | return fobj.getvalue() |
| 519 | finally: |
| 520 | fobj.close() |
| 521 | else: |
| 522 | # return None if the list is empty |
| 523 | return None |
| 524 | |
| 525 | |
| 526 | def tarbz2(self): |