using python with tar files and compressed files

Discussion in 'Python' started by John Salerno, Aug 9, 2006.

  1. John Salerno

    John Salerno Guest

    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)
     
    John Salerno, Aug 9, 2006
    #1
    1. Advertising

  2. John Salerno

    Guest

    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)
     
    , Aug 9, 2006
    #2
    1. Advertising

  3. John Salerno

    John Machin Guest

    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
     
    John Machin, Aug 10, 2006
    #3
  4. John Salerno

    John Salerno Guest

    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.
     
    John Salerno, Aug 10, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Claudio Grondi
    Replies:
    4
    Views:
    583
    Claudio Grondi
    Aug 20, 2005
  2. Replies:
    2
    Views:
    447
    Michael Hoffman
    Apr 24, 2007
  3. Ray Van Dolson
    Replies:
    0
    Views:
    342
    Ray Van Dolson
    Sep 23, 2009
  4. Ray Van Dolson
    Replies:
    0
    Views:
    849
    Ray Van Dolson
    Sep 25, 2009
  5. benoit Guyon
    Replies:
    2
    Views:
    234
    benoit Guyon
    Jul 26, 2005
Loading...

Share This Page