""" converts a permission mask in symbolic format (ex.: drwxr-xr-x) to a string that's usable in a chmod command ex.: chmod u=rwx,g=,o= ~/myscripts/convert_mask.py Created by Bert Heymans on 2006-10-12. This code is public domain. """ class SymbolicPermission: def __init__(self, symbolicString): """ split up into user, group, other """ self.user = symbolicString[1:4] self.group = symbolicString[4:7] self.other = symbolicString[7:10] pass def toUsableString(self): """ format to a usable string, that can be used in a chmod command ex.: u=rwx,g=,o= """ def replaceAll(perm): perm = perm.replace('-','') perm = perm.replace('s','sx') perm = perm.replace('t','tx') # don't reverse order of S and s replacement (obvious) perm = perm.replace('S','s') perm = perm.replace('T','t') return perm self.user = replaceAll(self.user) self.group = replaceAll(self.group) self.other = replaceAll(self.other) return "u=%s,g=%s,o=%s" % (self.user, self.group, self.other)