Home  
Login
Username:

Password:

Remember me



Lost Password?

Register now!
Sections
Who's Online
26 user(s) are online (15 user(s) are browsing Forums)

Members: 0
Guests: 26

more...
Support us!
Recent OS4 Files
OS4Depot.net





Python:Lib/amigapath.py bugs?
Quite a regular
Joined:
2009/2/9 19:32
From Brussels Belgium
Posts: 861
With the following python script ospath.py i reproduced error messages that trace backt to the amigapath.py module

import os
import stat
fileStats = os.stat ( 'Arch.gc' ) # a file in the current directory
#if os.path.isdir ( fileStats ):
# print 'Directory.'
#if os.path.isfile ( fileStats ):
# print 'File.'
#if os.path.islink ( fileStats ):
# print 'Shortcut.'
if os.path.ismount ( fileStats ):
print 'Mount point.'

The following results are given when uncommenting successively the 4 if blocks

11.Datas:Gui4Cli/GuiCreator> python:scripts/ospath.py
Traceback (most recent call last):
File "python:scripts/ospath.py", line 4, in <module>
if os.path.isdir ( fileStats ):
File "PYTHON:Lib/amigapath.py", line 204, in isdir
st = os.stat(path)
TypeError: coercing to Unicode: need string or buffer, amiga.stat_result found

11.Datas:Gui4Cli/GuiCreator> python:scripts/ospath.py
Traceback (most recent call last):
File "python:scripts/ospath.py", line 6, in <module>
if os.path.isfile ( fileStats ):
File "PYTHON:Lib/amigapath.py", line 217, in isfile
st = os.stat(path)
TypeError: coercing to Unicode: need string or buffer, amiga.stat_result found

11.Datas:Gui4Cli/GuiCreator> python:scripts/ospath.py
Traceback (most recent call last):
File "python:scripts/ospath.py", line 8, in <module>
if os.path.islink ( fileStats ):
File "PYTHON:Lib/amigapath.py", line 165, in islink
st = os.lstat(path)
TypeError: coercing to Unicode: need string or buffer, amiga.stat_result found

11.Datas:Gui4Cli/GuiCreator> python:scripts/ospath.py
Traceback (most recent call last):
File "python:scripts/ospath.py", line 10, in <module>
if os.path.ismount ( fileStats ):
File "PYTHON:Lib/amigapath.py", line 257, in ismount
s1 = os.stat(path)
TypeError: coercing to Unicode: need string or buffer, amiga.stat_result found








   Report Go to top

Re: Python:Lib/amigapath.py bugs?
Just can't stay away
Joined:
2006/12/6 21:18
From Michigan
Posts: 1027
@JosDuchIt

With the following python script ospath.py i reproduced error messages that trace backt to the amigapath.py module....

Did you start off with ...

Python-Docs-2.5/lib/module-stat.html
11.3 stat -- Interpreting stat() results

"The stat module defines constants and functions for interpreting the results of os.stat(), os.fstat() and os.lstat() (if they exist). For complete details about the stat(), fstat() and lstat() calls, consult the documentation for your system. ..."


There's a sample script for 'walking a dir tree', but it's too technical for me. I don't know if even the file Stat'mode' is supported. I suspect it doesn't exist. Does it?


   Report Go to top

Re: Python:Lib/amigapath.py bugs?
Quite a regular
Joined:
2009/2/9 19:32
From Brussels Belgium
Posts: 861
This works OK:

=====
import stat
import os
fileStats = os.stat ( 'Sys:' )
if stat.S_ISREG ( fileStats [ stat.ST_MODE ] ):
print 'Regular file.'
elif stat.S_ISDIR ( fileStats [ stat.ST_MODE ] ):
print 'Directory.'
=======

so my guess is that the problem is in amigapath.py

   Report Go to top

Re: Python:Lib/amigapath.py bugs?
Just can't stay away
Joined:
2006/12/4 23:15
Posts: 1482
Hmmm

So you're passing the result of os.stat to os.path.isdir()

Quote:

os.path.isdir(path)
Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.


Quote:

os.stat(path)
Perform the equivalent of a stat() system call on the given path. (This function follows symlinks; to stat a symlink use lstat().)

The return value is an object whose attributes correspond to the members of the stat structure, namely:

st_mode - protection bits,
st_ino - inode number,
st_dev - device,
st_nlink - number of hard links,
st_uid - user id of owner,
st_gid - group id of owner,
st_size - size of file, in bytes,
st_atime - time of most recent access,
st_mtime - time of most recent content modification,
st_ctime - platform dependent; time of most recent metadata change on Unix, or the time of creation on Windows)
...
...


os.stat returns an amiga.stat_result object whereas os.path.isdir takes a path, ie a string / buffer.

Unless a stat result is supposed to convert to string automatically there is no bug in this context, rather you code is an incorrect usage of stat.

Checking gainst python on my linux box I get identical behaviour.

I would be tempted to say RTFM but that would be rude of me

_________________
Blender For OS4.x : Blues : Walker Broad
   Report Go to top

Re: Python:Lib/amigapath.py bugs?
Quite a regular
Joined:
2009/2/9 19:32
From Brussels Belgium
Posts: 861
As a newbee to python i just copied examples from a website. Looks like i was too confident here.

My mistake was due to the fact that i did not get an error message for the line in error, but that the msg pointed to a lib script.
While this is probably not only a python problem, i am not accustomed to it. Well, i am reading more than i can digest obviously :(

   Report Go to top

Re: Python:Lib/amigapath.py bugs?
Just can't stay away
Joined:
2006/12/4 23:15
Posts: 1482
Quote:

As a newbee to python i just copied examples from a website. Looks like i was too confident here.


Sounds like it was a bad example! Trouble with the net, there a lot of chaff along with the grain!

Quote:

My mistake was due to the fact that i did not get an error message for the line in error, but that the msg pointed to a lib script.


This can often happen with scripted languages. Modules of this type effectively become part of your script.

Quote:

While this is probably not only a python problem, i am not accustomed to it. Well, i am reading more than i can digest obviously :(


On the contrary, read more, and keep asking questions. No doubt you allready know but in case you don't the python manual is here:

http://docs.python.org/release/2.5/lib/lib.html

The main docs for later versions are slightly easier to read, and are mostly relavent but ofcourse you must be wary of changes / additions

http://docs.python.org


_________________
Blender For OS4.x : Blues : Walker Broad
   Report Go to top

Re: Python:Lib/amigapath.py bugs?
Just can't stay away
Joined:
2006/12/6 21:18
From Michigan
Posts: 1027
>JosDuchit #1
fileStats = os.stat ( 'Arch.gc' ) # a file in the current directory
The argument is wrong. It's 'os.stat(path)'. Try this at home:

#Amiga Python 53.29
import os
st = os.stat( "Ram:")
print st
>>>>
(16832, 0, 1822471436, 2, 0, 0, 0L, 1308634305, 1308634305, 1308634305, 1308634305, 1308634305, 1308634305, 512, 0L, 0)

The "STAT" module says -- 'All the variables below are simply symbolic indexes into the 10-tuple returned by os.stat(), os.fstat() or os.lstat().'

Well, it's a 16 tuple isn't it? I looked at help(os.stat_results) and the 'stavfs' module and can't determine what the tuple is saying.

>broadblues
I would be tempted to say RTFM but that would be rude of me ...
It sure would considering the depth of 2.5s Docs list. I read all the time, and it just too deep for one person to know all of it!

   Report Go to top

Re: Python:Lib/amigapath.py bugs?
Quite a regular
Joined:
2009/2/9 19:32
From Brussels Belgium
Posts: 861

@snuffy

I found this:
file:///PYTHON/Python-Docs-2.5.1/lib/os-file-dir.html
"stat( path)
Perform a stat() system call on the given path. The return value is an object whose attributes correspond to the members of the stat structure, namely: st_mode (protection bits), st_ino (inode number), st_dev (device), st_nlink (number of hard links), st_uid (user ID of owner), st_gid (group ID of owner), st_size (size of file, in bytes), st_atime (time of most recent access), st_mtime (time of most recent content modification), st_ctime (platform dependent; time of most recent metadata change on Unix, or the time of creation on Windows):"

10 elements given, the example in this doc does not match your tuple (16 items)
For the Amiga all the times are the same: date of last change
still i wonder what the last elements of the tuple are.

I am glad i'm not the only one having problems with the learning curve

   Report Go to top

Re: Python:Lib/amigapath.py bugs?
Just can't stay away
Joined:
2006/12/4 23:15
Posts: 1482
@Snuffy
Quote:

I would be tempted to say RTFM but that would be rude of me ...
It sure would considering the depth of 2.5s Docs list. I read all the time, and it just too deep for one person to know all of it!


Sure, but that's why I added a smiley

However, when I'm scripting, I find myslef googling every other function even though I'm relativley experienced in the languages I use (mostly php script wise ATM, but the principle holds across all languages). You don;t have to read the whole manual, but reading it little and often, saves more time than it takes to read it.



_________________
Blender For OS4.x : Blues : Walker Broad
   Report Go to top





[Advanced Search]


Powered by XOOPS 2.0 © 2001-2014 The XOOPS Project