Understanding CHMOD

Tim Daneliuk tundra at tundraware.com
Fri Feb 13 04:30:07 EST 2004


Fuzzyman wrote:

> Ok.... so I might be a windoze user trying to program CGIs for a Linux
> server.... but Python doesn't seem to go out of it's way to make
> understanding file attributes difficult. The python manual is
> appalling in this are a :-(

These are Unix-style permissions and the right place to
get more info would be a Unix OS man page for 'chmod'.

As it happens, last year, I wrote a Python program that
examines file attributes portably across Win32 and Unix.
You can have a look at the code that does this (among many
other things) at:

http://www.tundraware.com/Software/twander/


> 
> Anyway - I think I've finally worked out that the correct way to get
> (rather than set) the mode of a file is :
> 
> from stat import *
> S_IMODE(os.stat(filepath)[ST_MODE])
> 
> Obvious huh !
> 
> The result will be some bitmasked combination of the following ?
> 
> statlist = [S_ISUID, S_ISGID, S_ENFMT, S_ISVTX, S_IREAD, S_IWRITE,
> S_IEXEC, S_IRWXU, S_IRUSR, S_IWUSR, S_IXUSR, S_IRWXG,
>  S_IRGRP, S_IWGRP, S_IXGRP, S_IRWXO, S_IROTH, S_IWOTH, S_IXOTH]
> 
> Which mean ??????
> 
> Having obtained a result from S_IMODE(os.stat(filepath)[ST_MODE]), how
> do I work out what it means ?
> 
> Thanks.
> 
> Fuzzy
> 
> http://www.voidspace.org.uk/atlantibots/pythonutils.html


-- 
----------------------------------------------------------------------------
Tim Daneliuk     tundra at tundraware.com
PGP Key:         http://www.tundraware.com/PGP/



More information about the Python-list mailing list