Build error Python 2.4.1 - stat problem?

Brandt, Servatius Servatius.Brandt at fujitsu-siemens.com
Wed May 25 03:30:04 EDT 2005


Donn Cave wrote:

>In article <mailman.56.1116946912.18027.python-list at python.org>,
> <Servatius.Brandt at fujitsu-siemens.com> wrote:
>...
>> I used the python executable from the build directory to run the
>> following program:
>> 
>>     import os
>> 
>>     def main():
>>         if not (os.path.exists("/")):
>>             print "/ does not exist"
>>         else:
>>             print "/ exists"
>>         if not (os.path.isdir("/")):
>>             print "/ is not a directory"
>>         else:
>>             print "/ ok"
>>     
>>     if   name   == "  main  ":
>>         main()
>> 
>> The output is:
>> 
>>     / exists
>>     / is not a directory
>> 
>> It's the same for every (existing) directory name I try: 
>os.path.isdir()
>> always returns false.
>> 
>> It looks as if the stat results are not recognised: os.path.exists()
>> works, but all the functions os.path.isdir(), os.path.isfile() etc.
>> don't.
>> 
>> Could anyone help me to solve the problem?
>
>Unless there are other Reliant users here ahead of you, some
>of it is going to be up to you.  If you follow isdir() back,
>you'll find some hard-coded octal bitmask definitions, including
>S_IFDIR = 0040000.
>
>Check it out.  Try to use that value the way they're using it,
>in C and in Python, and print out all the values involved.
>At worst, if C comes out wrong too, you may have a question
>that the vendor will be more likely to respond to.

First, thanks very much for your help.  On the Reliant Unix system,
C and Python both use the value you mention above.

I added some debug prints to isdir in Lib/posixpath.py in the build
tree:

    def isdir(path):
	"""Test whether a path is a directory"""
	try:
	    st = os.stat(path)
	    print "isdir: OK, path: %s" % path
	    print "st: %s" % st
	    print "size, mtime, atime, ctime, dev, ino:"
	    print "%s %s %s %s %s %s" % (st.st_size, st.st_mtime,
st.st_atime, st.st_ctime, st.st_dev, st.st_ino)
	except os.error:
	    print "isdir: OS.ERROR, path: %s" % path
	    return False
	return stat.S_ISDIR(st.st_mode)

and to S_ISDIR in Lib/stat.py:

    def S_ISDIR(mode):
	print "S_ISDIR: S_IFMT(mode): %s, S_IFDIR: %d" % (S_IFMT(mode),
S_IFDIR)
	print "mode: %s" % mode
	return S_IFMT(mode) == S_IFDIR

Then my sample program (see quote above) produces the following output:

    isdir: OK, path: /usr/local/lib/python2.4/site-packages
    st: (2, 1088705490076141L, 1050758L, 0, 1, 0, 4797493958154069376L,
870000000, 870000000, 0)
    size, mtime, atime, ctime, dev, ino:
    4797493958154069376 870000000 870000000 0 1050758 1088705490076141
    S_ISDIR: S_IFMT(mode): 0, S_IFDIR: 16384
    mode: 2
    isdir: OK, path: /usr/local/lib/site-python
    st: (2, 1088653950468589L, 1050758L, 0, 1, 0, 4797493958164069376L,
880000000, 880000000, 0)
    size, mtime, atime, ctime, dev, ino:
    4797493958164069376 880000000 880000000 0 1050758 1088653950468589
    S_ISDIR: S_IFMT(mode): 0, S_IFDIR: 16384
    mode: 2
    / exists
    isdir: OK, path: /
    st: (48, 8589951469L, 1050752L, 0, 0, 0, 4797500748297364352L,
120000000, 120000000, 6)
    size, mtime, atime, ctime, dev, ino:
    4797500748297364352 120000000 120000000 6 1050752 8589951469
    S_ISDIR: S_IFMT(mode): 0, S_IFDIR: 16384
    mode: 48
    / is not a directory

The stat values do not make any sense.  It seems that the value used for
the mode is really the numbers of links (I created the two empty
/usr/local... directories to prevent the os.error exception):

    $ ls -ldi /usr/local/lib/python2.4/>
	 2 drwxr-xr-x  48 root     root        2560 May 14 09:02 /
    253484 drwxr-xr-x   2 root     other         96 May 25 08:46
/usr/local/lib/python2.4/site-packages
    253472 drwxr-xr-x   2 root     other         96 May 25 08:46
/usr/local/lib/site-python

I'm a very beginner with Python and I'm not at all familiar with the
build structure of Python. (I just wanted to setup a Subversion
repository and to run some contributed Python hook scripts.)  It would
be very helpful if you could give me some hint in which source and
function the C stat() results are mapped to the stat values accessible
from Python.  Then I can try a bit debugging there.

- Servatius

------------------------------------------------------------------------
Servatius Brandt             Phone: +49 89 636-41504
Fujitsu Siemens Computers    Fax:   +49 89 636-48716
EP SW AD C++                 Email: Servatius.Brandt at fujitsu-siemens.com



More information about the Python-list mailing list