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 :-(
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/atlantib...thonutils.html 6 11470
What's your question? I think you need to look at the chmod(1) and
chmod(2) Linux man pages, not a Python manual.
On 13 Feb 2004 00:55:30 -0800, 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 :-(
The library reference seems to detail all the points that were confusing
you. The documentation for the 'stat' module in particular seems pretty
explicit:
<http://www.python.org/doc/current/lib/module-stat.html>
--
\ "There is no reason anyone would want a computer in their |
`\ home." -- Ken Olson, president, chairman and founder of |
_o__) Digital Equipment Corp., 1977 |
Ben Finney <http://bignose.squidly.org/>
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/atlantib...thonutils.html
--
----------------------------------------------------------------------------
Tim Daneliuk tu****@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
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 :-(
agreed
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 ?
These are the basic access permissions.
S_IRGRP
S_IROTH
S_IRUSR
S_IWGRP
S_IWOTH
S_IWUSR
S_IXGRP
S_IXOTH
S_IXUSR
There are some shortcut (confusing IMHO) entries:
S_IEXEC = S_IXUSR
S_IWRITE = S_IWUSR
S_IREAD = S_IRUSR
S_IRWXG = stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP
S_IRWXO = stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH
S_IRWXU = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
The rest are "extended" attribute bits
and file type bits.
Here's a simplified ls access listing in python:
#!/usr/bin/env python
import sys
import stat
import os
filename=sys.argv[1]
mode=stat.S_IMODE(os.lstat(filename)[stat.ST_MODE])
perms="-"
for who in "USR", "GRP", "OTH":
for what in "R", "W", "X":
if mode & getattr(stat,"S_I"+what+who):
perms=perms+what.lower()
else:
perms=perms+"-"
print perms + " " + filename
--
Pádraig Brady - http://www.pixelbeat.org
[snip..] These are the basic access permissions.
S_IRGRP S_IROTH S_IRUSR
S_IWGRP S_IWOTH S_IWUSR
S_IXGRP S_IXOTH S_IXUSR
There are some shortcut (confusing IMHO) entries:
S_IEXEC = S_IXUSR S_IWRITE = S_IWUSR S_IREAD = S_IRUSR
S_IRWXG = stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP S_IRWXO = stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH S_IRWXU = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
The rest are "extended" attribute bits and file type bits.
Here's a simplified ls access listing in python:
#!/usr/bin/env python
import sys import stat import os
filename=sys.argv[1] mode=stat.S_IMODE(os.lstat(filename)[stat.ST_MODE]) perms="-" for who in "USR", "GRP", "OTH": for what in "R", "W", "X": if mode & getattr(stat,"S_I"+what+who): perms=perms+what.lower() else: perms=perms+"-" print perms + " " + filename
Thanks for your help !
I always find it slightly surprising when I get a reply that actually
answers the question ;-)
Fuzzy http://www.voidspace.org.uk/atlantib...htonutils.html
Tim Daneliuk <tu****@tundraware.com> wrote in message news:<bf************@eskimo.tundraware.com>... 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/
Thanks very much.
I'll have a look - much appreciated.
Fuzzy http://www.voidspace.org.uk/atlantib...htonutils.html
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/atlantib...thonutils.html
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Daniel |
last post by:
Hi,
From what I read from the PHP manual, chmod on a Windows platform
should have no effect, and that seems totally normal (unless someone on
sourceforge has a windows port of that!).
I...
|
by: Xuan Yuan |
last post by:
I'm using Windows XP Professional and have no FTP installed. Instead, I use Command Promt. I need to CHMOD a PHP file, so I type "CHMOD 775 file-path",but get "'CHMOD'is not recognized as an internal...
|
by: Ian N |
last post by:
Hi i'm having a problem with file permissions of upload, they appear to
be being set to only readable by the administrator, so anyone browsing
the site gets a 403 forbidden error when they try and...
|
by: Stewart |
last post by:
Hi, I'm working on a program in VC++ right now that needs to set file
permissions of a given file to 766 (read/write/execute). Now I've found
the _chmod() function in the API help docs, but that...
|
by: Freebird |
last post by:
Hello everyone, =]
I need your help,
I'm creating a script that will work in many servers, and there's this part,
where you can update a list, so the script goes from the client's machine to...
|
by: James Colannino |
last post by:
Ok, so now I have a very interesting problem, this time related to
os.chmod. I have the following in a text file: 0600. My script reads
that number as a string and converts it to an integer for...
|
by: webhead |
last post by:
I have a web where users can upload photos, but they want to also be able to delete them. The directory can have chmod changes but it won't let me chmod the files and unlink them. I'm assuming it...
|
by: Rik |
last post by:
Hello,
first of all, my provider sucks, newsserver is down for the #nth time
now, offcourse when I have an urgent question.... So this will be me
first time using Google Groups, forgive me if...
|
by: lawrence k |
last post by:
I've a simple script to transfer some files from one domain to
another, with both domains living on the same server. The files in
both directories are already chmod 777. Yet after transfer, I try...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |