Re: [Tutor] tarfile +stdin

2006-12-19 Thread wesley chun
>  >>> tbz.add(sys.stdin)
> Traceback (most recent call last):
>File "", line 1, in 
>  :
>  return s.startswith('/')
> AttributeError: 'file' object has no attribute 'startswith'


altho i cannot help you with your original query, i *can* tell you
that the reason why you get the error is that add() expects a filename
(not a file object).  i think that you have to create a TarInfo object
and use the addfile() method instead but can't confirm that.  anyone
else know?

thanks,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] tarfile +stdin

2006-12-19 Thread Martin Marcher

Hello,

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
...
myfile.dmp
>>>

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

>>> import sys
>>> tbz.add(sys.stdin)
Traceback (most recent call last):
  File "", line 1, in 
  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
thanks
martin



smime.p7s
Description: S/MIME cryptographic signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor