Question:
How to effectively use the stat function to obtain meaningful access rights to files (User, Group and Other).
Details:
I am asking for permissions for files like this:
statInfo = os.stat permissions = stat.S_IMODE ( os.stat ( 'fooBar.txt' ).st_mode )
Returns permissions in decimal form. Therefore, if fooBar.txt has permissions for the octal file 0700 , here the permissions are set to decimal 448 . I want to set 9 variables for each permission ( ownerRead , ownerWright , ownerExecute , groupRead , ...) If I were going to do this, I would use brute force
statInfo = os.stat permissions = stat.S_IMODE ( os.stat ( 'fooBar.txt' ).st_mode ) octPermissions = oct ( permissions ) ownerRead = octPermissions [1] >= 4 ownerWrite = octPermissions [1] == 2 or octPermissions [1] == 6 or octPermissions [1] == 3 or ownerExecute = octPermissions [1] == 1 or octPermissions [1] == 5 or octPermissions [1] == 3
Is there a more efficient way to do this without having to convert to octal, since this function will be called quite a bit?
source share