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

Method tarbz2

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

return a data stream of the files in tar format, compressed with bzip2. Returns None if the list is empty.

(self)

Source from the content-addressed store, hash-verified

524
525
526 def tarbz2(self):
527 """
528 return a data stream of the files in tar format, compressed
529 with bzip2.
530 Returns None if the list is empty.
531 """
532 import tarfile, cStringIO, bz2
533 fobj = cStringIO.StringIO()
534 # make sure the list contains something
535 if len(self) >= 0:
536 try:
537 tar = tarfile.open('', "w", fobj)
538 except:
539 sys.stderr.write("Can't open file for bzip2 compression.")
540 raise
541 try:
542 for name in self:
543 # only add files
544 if os.path.isfile(name):
545 try:
546 tar.add(name)
547 except ValueError:
548 # it can't store extremely long names
549 # so tell which ones and continue
550 # TODO: MAYBE TRY TRUNCATING NAMES HERE
551 sys.stderr.write('Warning: Unable to store: ')
552 sys.stderr.write(name)
553 sys.stderr.write('\n')
554 tar.close()
555 # I compress using bzip2 only at this point
556 # because I get an error if I try to do it with
557 # tarfile.open. It says file-like objects aren't
558 # supported.
559 return bz2.compress(fobj.getvalue())
560 finally:
561 fobj.close()
562 else:
563 # return None if the list is empty.
564 return None
565
566 def tar(self):
567 """

Callers 1

recipe-259147.pyFile · 0.80

Calls 7

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

Tested by

no test coverage detected