Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > using python with tar files and compressed files

Reply
Thread Tools

using python with tar files and compressed files

 
 
John Salerno
Guest
Posts: n/a
 
      08-09-2006
Here's the name of a file I have: wxPython-newdocs-2.6.3.3.tar.bz2

Now, I tried this:

import tarfile
tar = tarfile.open('wxPython-newdocs-2.6.3.3.tar.bz2', 'r:bz2')

but got this:

Traceback (most recent call last):
File "<pyshell#5>", line 1, in -toplevel-
tar = tarfile.open('wxPython-newdocs-2.6.3.3.tar.bz2', 'r:bz2')
File "C:\Python24\lib\tarfile.py", line 901, in open
return func(name, filemode, fileobj)
File "C:\Python24\lib\tarfile.py", line 1006, in bz2open
raise ReadError, "not a bzip2 file"
ReadError: not a bzip2 file

So I'm a little confused. When dealing with a tar.gz or tar.bz2 file, do
you need to uncompress it first with the proper module (gzip or bz2)? Or
does tarfile take care of this? If so, why doesn't it recognize the
above file? Or am I just doing it the wrong way? (I'm following an
example in the docs)
 
Reply With Quote
 
 
 
 
enigmadude@rock.com
Guest
Posts: n/a
 
      08-09-2006
This syntax works on other bzipped tar files. But it's not unheard of
that large tarballs will get corrupted from a download mirror. Use a
download manager and try redownloading the file. Usually a mirror will
include an md5sum text file so that you can compare the checksum to
your downloaded file to verify its integrity. For some reason, the
wxPython site doesn't have them.

John Salerno wrote:
> Here's the name of a file I have: wxPython-newdocs-2.6.3.3.tar.bz2
>
> Now, I tried this:
>
> import tarfile
> tar = tarfile.open('wxPython-newdocs-2.6.3.3.tar.bz2', 'r:bz2')
>
> but got this:
>
> Traceback (most recent call last):
> File "<pyshell#5>", line 1, in -toplevel-
> tar = tarfile.open('wxPython-newdocs-2.6.3.3.tar.bz2', 'r:bz2')
> File "C:\Python24\lib\tarfile.py", line 901, in open
> return func(name, filemode, fileobj)
> File "C:\Python24\lib\tarfile.py", line 1006, in bz2open
> raise ReadError, "not a bzip2 file"
> ReadError: not a bzip2 file
>
> So I'm a little confused. When dealing with a tar.gz or tar.bz2 file, do
> you need to uncompress it first with the proper module (gzip or bz2)? Or
> does tarfile take care of this? If so, why doesn't it recognize the
> above file? Or am I just doing it the wrong way? (I'm following an
> example in the docs)


 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      08-10-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> This syntax works on other bzipped tar files. But it's not unheard of
> that large tarballs will get corrupted from a download mirror. Use a
> download manager and try redownloading the file. Usually a mirror will
> include an md5sum text file so that you can compare the checksum to
> your downloaded file to verify its integrity. For some reason, the
> wxPython site doesn't have them.
>
> John Salerno wrote:
> > Here's the name of a file I have: wxPython-newdocs-2.6.3.3.tar.bz2
> >
> > Now, I tried this:
> >
> > import tarfile
> > tar = tarfile.open('wxPython-newdocs-2.6.3.3.tar.bz2', 'r:bz2')
> >
> > but got this:
> >
> > Traceback (most recent call last):
> > File "<pyshell#5>", line 1, in -toplevel-
> > tar = tarfile.open('wxPython-newdocs-2.6.3.3.tar.bz2', 'r:bz2')
> > File "C:\Python24\lib\tarfile.py", line 901, in open
> > return func(name, filemode, fileobj)
> > File "C:\Python24\lib\tarfile.py", line 1006, in bz2open
> > raise ReadError, "not a bzip2 file"
> > ReadError: not a bzip2 file
> >
> > So I'm a little confused. When dealing with a tar.gz or tar.bz2 file, do
> > you need to uncompress it first with the proper module (gzip or bz2)? Or
> > does tarfile take care of this? If so, why doesn't it recognize the
> > above file? Or am I just doing it the wrong way? (I'm following an
> > example in the docs)


Another check on download corruption would be to use the "test
integrity" option on the stand-alone bzip2 executable [which may
already be on your machine, or can be obtained (directly or in source
which you'd compile) from www.bzip2.org]:

bzip2 -t yourfile

HTH,
John

 
Reply With Quote
 
John Salerno
Guest
Posts: n/a
 
      08-10-2006
(E-Mail Removed) wrote:
> This syntax works on other bzipped tar files. But it's not unheard of
> that large tarballs will get corrupted from a download mirror. Use a
> download manager and try redownloading the file. Usually a mirror will
> include an md5sum text file so that you can compare the checksum to
> your downloaded file to verify its integrity. For some reason, the
> wxPython site doesn't have them.


Well, unless the file was updated between my problem and when I got
home, then perhaps it was my system. Because I tried it again on Linux
and it worked as expected.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Pipelining tar create and tar extract the "Python" way... Ray Van Dolson Python 0 09-25-2009 03:48 PM
Pipelining tar create and tar extract the "Python" way... Ray Van Dolson Python 0 09-23-2009 10:52 PM
os.system('tar -c * | tar -C dst') ##Any other suggestions... list.repository@gmail.com Python 2 04-24-2007 10:29 PM
Version of TAR in tarfile module? TAR 1.14 or 1.15 port to Windows? Claudio Grondi Python 4 08-20-2005 08:01 PM
trouble with Archive::Tar : Can not read compressed format in tar-mode benoit Guyon Perl Misc 2 07-26-2005 01:53 PM



Advertisments