MCPcopy Create free account
hub / github.com/ActiveState/code / tar

Method tar

recipes/Python/259147_FSList/recipe-259147.py:566–599  ·  view source on GitHub ↗

return a data stream of the files in uncompressed tar format. Returns None if the list is empty.

(self)

Source from the content-addressed store, hash-verified

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
602if __name__ == '__main__':

Callers 1

recipe-259147.pyFile · 0.80

Calls 6

isfileMethod · 0.80
openMethod · 0.45
writeMethod · 0.45
addMethod · 0.45
closeMethod · 0.45
getvalueMethod · 0.45

Tested by

no test coverage detected