#1
  1. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12

    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.
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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:

    http://www.python.org/doc/2.3.4/lib/module-popen2.html

    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!

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Alternatively you could use os.chmod, os.stat function and stat module:

    Code:
    import os
    import stat
    fstat = os.stat("somefile path")
    print "Permissions are:", oct(stat.S_IMODE(fstat[stat.ST_MODE]))
    Change a file objects permissions:
    Code:
    os.chmod("some file path",0777)
    Assuming the installer has permission to modify permissions in the first place

    grim
    Last edited by Grim Archon; September 27th, 2004 at 07:02 AM.

IMN logo majestic logo threadwatch logo seochat tools logo