The following function will achieve this, given some common circumstances (i.e. I have not tested it under Windows or SELinux).
import stat def permissions_to_unix_name(st_mode): permstr = '' usertypes = ['USR', 'GRP', 'OTH'] for usertype in usertypes: perm_types = ['R', 'W', 'X'] for permtype in perm_types: perm = getattr(stat, 'S_I%s%s' % (permtype, usertype)) if st_mode & perm: permstr += permtype.lower() else: permstr += '-' return permstr
This creates the main string on demand. However, this can also be improved to display additional data, for example. be it a directory ( d ) or a symbolic link ( l ). Feel free to improve it.
javex
source share