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

Method targz

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

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

(self)

Source from the content-addressed store, hash-verified

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):

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