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
How to convert a stat output to a unix permissions string