Checking File Permissions in Linux with Python -
I am writing a script to check permissions for files in user's directories and if they are not acceptable then I I will warn them, but I just do not have permission from the logged-in user, but I also want to see the group and others. how can I do this? I think that Python in .access () can only check the permissions for the user running the script.
You are right that, like the underlying syscall, the specific user (effective to help in semolina situations Checks Actual instead of ID)
The correct way to get more general information about this is to allow the osstat
return file with a file, per user, group, and other permissions for the bits of st_mode
is the attribute.
To help explain those bits, you should use the module specifically, you want to define bitmask, and you want to mask the related bits in st_mode
To use them, use the and
operator (bit-more). Attribute - For example, if you need a definitive / incorrect probe, if a certain file is group-readable, then one method is:
import import def def isgroupreadable (filepath) ): St = Os.stat (filepath) Return boole (st.st_mode and stat.S_IRGRP)
Note: osstat
calls can be expensive, So instead of repeating the call of every interest, make sure to remove all the information you care about a single call;).
Comments
Post a Comment