September 26th, 2004, 01:00 PM
Checking file permission on *nix, how?
I have a CGI script, I want to make an installer, it will check each file in the file structure of the program and if that file (or dir) doesn't exist it will create it. I also need to check permissions, how can I? I need to make sure that a specific dir requires read + write, and that another only has read.. etc. I don't want to attempt to read from file to see if I have permission.
September 27th, 2004, 12:15 AM
Your best bet would probably be to use os.popen() if you want to send commands to the command line and get the results, but I'd sugest that you check out the popen2 module too:
Also, if I can make a sugestion. Instead of checking and then setting the file permissions if you need to, it would probably be better to just assume you don't have the file permisions you want and chmod them to what you want.
Sounds like a fun project!
September 27th, 2004, 05:59 AM
Alternatively you could use os.chmod, os.stat function and stat module:
Change a file objects permissions:
fstat = os.stat("somefile path")
print "Permissions are:", oct(stat.S_IMODE(fstat[stat.ST_MODE]))
Assuming the installer has permission to modify permissions in the first place
os.chmod("some file path",0777)
Last edited by Grim Archon; September 27th, 2004 at 06:02 AM.