return a data stream of the files in uncompressed tar format. Returns None if the list is empty.
(self)
| 564 | return None |
| 565 | |
| 566 | def tar(self): |
| 567 | """ |
| 568 | return a data stream of the files in uncompressed tar format. |
| 569 | Returns None if the list is empty. |
| 570 | """ |
| 571 | import cStringIO, tarfile |
| 572 | fobj = cStringIO.StringIO() |
| 573 | # check the list contains something |
| 574 | if len(self) >= 0: |
| 575 | try: |
| 576 | tar = tarfile.open('', "w", fobj) |
| 577 | except: |
| 578 | sys.stderr.write("Unable to open tar file.") |
| 579 | raise |
| 580 | try: |
| 581 | for name in self: |
| 582 | # only add files |
| 583 | if os.path.isfile(name): |
| 584 | try: |
| 585 | tar.add(name) |
| 586 | except ValueError: |
| 587 | # it can't store extremely long names |
| 588 | # so tell which ones and continue |
| 589 | sys.stderr.write('Warning: Unable to store: ') |
| 590 | sys.stderr.write(name) |
| 591 | sys.stderr.write('\n') |
| 592 | tar.close() |
| 593 | return fobj.getvalue() |
| 594 | finally: |
| 595 | fobj.close() |
| 596 | |
| 597 | else: |
| 598 | # return None if the list is empty |
| 599 | return None |
| 600 | |
| 601 | |
| 602 | if __name__ == '__main__': |