[Tutor] tarfile +stdin

Martin Marcher martin.marcher at openforce.com
Tue Dec 19 18:36:15 CET 2006


I'm trying to create a backup script which in one of the last steps  
is to create a tarball that is possibly gzipped or bzipped2.

 >>> import tarfile
 >>> tbz = tarfile.open(name="tarfile.tar.bz2", mode="w:bz2")
 >>> tbz.add("myfile.dmp")
 >>> for tarinfo in tbz:
...     print tarinfo.name

Now how would I open stdin to add files to this tarball?

 >>> import sys
 >>> tbz.add(sys.stdin)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/tarfile.py", line 1333, in add
     and os.path.abspath(name) == os.path.abspath(self.name):
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/posixpath.py", line 403, in abspath
     if not isabs(path):
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/posixpath.py", line 49, in isabs
     return s.startswith('/')
AttributeError: 'file' object has no attribute 'startswith'

happy about all hints

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2474 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20061219/d772ec30/attachment.bin 

More information about the Tutor mailing list