Topic: Baffling tarfile.is_tarfile behaviour

I am getting some very odd behaviour in one of my python scripts...
I have a tar.bz2 file which, in my script is not being recognised ie

tarfile.is_tarfile(myfilepath)

is returning False.

The file definitely exists and is a valid file. The bizarre thing is that when I test that file in both a standalone script and running python from the commandline, is_tarfile returns True (as it should).

I really don't know what could be causing it to return False in my main script - can anyone offer any ideas on why it's misbehaving or thoughts on things I could investigate (or point out to me the obvious thing I'm missing if that's the case)?


Details (in case important):
I am using Python  2.7 on a Centos 5 machine.
I am running in a chroot jail entered using os.chroot() but my standalone test works fine both with and without the chroot command.
Nothing is wrong with the variable holding the filepath - os.path.exists(myfilepath) returns True.
I haven't modified tarfile in any way.
tarfile.is_tarfile is working fine for other (not tar.bz2) tar files .

Thumbs up

Re: Baffling tarfile.is_tarfile behaviour

sybre wrote:

I am using Python  2.7

python 2.7 sees it well
python 2.6 doesn't

print the python version by the script to be sure

Thumbs up

Re: Baffling tarfile.is_tarfile behaviour

Definitely using python 2.7 - sys.version confirms it.

Thumbs up

Re: Baffling tarfile.is_tarfile behaviour

[guest@localhost tests]$ tar -cjf t.tar.bz2 t.py
[guest@localhost tests]$ tar -tjf t.tar.bz2
t.py
[guest@localhost tests]$ python
Python 2.7 (r27:82500, Sep 16 2010, 18:03:06) 
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tarfile
>>> tarfile.is_tarfile('t.tar.bz2')
True
>>> 
[guest@localhost tests]$
sybre wrote:
tarfile.is_tarfile(myfilepath)

print myfilepath on the screen before the call

Thumbs up

Re: Baffling tarfile.is_tarfile behaviour

Have both printed myfilepath and done os.path.exists(myfilepath) - it's definitely fine.
Testing tarfile.is_tarfile(myfilepath) in a separate script works fine, just not in the main script.

Thumbs up