convert a symbolic permission string
9
This python class converts a permission mask in symbolic format (the kind a diretcory listing produces, ex.: drwxr-xr-x) to a string that's usable in a chmod command.
ex.: chmod u=rwx,g=rwx,o=rwtx ~/myscripts/convert_mask.py
This can be very useful when recovering permissions from a backup.
ex.: chmod u=rwx,g=rwx,o=rwtx ~/myscripts/convert_mask.py
This can be very useful when recovering permissions from a backup.
"""
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)






There are currently no comments for this snippet.