Skip to content

Commit

Permalink
symbolic description can be a list
Browse files Browse the repository at this point in the history
  • Loading branch information
open-dynaMIX committed Oct 30, 2015
1 parent 708f8a8 commit 4955e30
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
38 changes: 15 additions & 23 deletions src/action/chmodsym.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def chmod(path, actperms, description):
if not description:
return False

if isint(description):
if isinstance(description, basestring):
if handle_octal(path, actperms, description):
return True
else:
Expand Down Expand Up @@ -67,21 +67,22 @@ def handle_symbolic(path, actperms, description):
if chmod.regex is None:
chmod.regex = re.compile(r"^(?P<who>[ugo]*|[a]?)(?P<op>[+\-=])"
"(?P<value>[ugo]|[rwx]*)$")
mo = chmod.regex.match(description)
who, op, value = mo.group("who"), mo.group("op"), mo.group("value")
if not who:
who = "a"
mode = actperms[2]
modeold = mode
for person in who:
if value in ("o", "g", "u"):
mask = (ors((stat_bit(person, z) for z in "rwx"
if (mode & stat_bit(value, z)))))
else:
mask = ors((stat_bit(person, z) for z in value))
if op == "=":
mode &= ~ ors((stat_bit(person, z) for z in "rwx"))
mode = (mode & ~mask) if (op == "-") else (mode | mask)
for desc in description:
mo = chmod.regex.match(desc)
who, op, value = mo.group("who"), mo.group("op"), mo.group("value")
if not who:
who = "a"
for person in who:
if value in ("o", "g", "u"):
mask = (ors((stat_bit(person, z) for z in "rwx"
if (mode & stat_bit(value, z)))))
else:
mask = ors((stat_bit(person, z) for z in value))
if op == "=":
mode &= ~ ors((stat_bit(person, z) for z in "rwx"))
mode = (mode & ~mask) if (op == "-") else (mode | mask)

if mode == modeold:
return False
Expand Down Expand Up @@ -112,15 +113,6 @@ def ors(sequence, initial = 0):
return functools.reduce(operator.__or__, sequence, initial)


def isint(description):
try:
int(description)
except ValueError:
return False
else:
return True


# Test code

def test_code():
Expand Down
20 changes: 14 additions & 6 deletions src/configfile/check_chmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
def check_chmod(parser, section, what, debug):
if parser.has_option(section, what):
tempchmod = parser.get(section, what)
if verify_chmod(tempchmod):
chmod = tempchmod
chmod = verify_chmod(tempchmod)
if chmod:
if debug:
print >> sys.stderr, ("[debug] '%s' in section '%s' "
"is valid" % (what, section))
Expand All @@ -36,11 +36,19 @@ def verify_chmod(description):
if len(description) < 3 or len(description) > 4:
return False
else:
return True
return description
else:
p = re.compile(r"^([ugo]*|[a]?)([+\-=])([ugo]|[rwx]*)$")
if p.match(description):
return True
valid = True
symdesc = []
for sym in description.split(','):
sym = sym.strip()
p = re.compile(r"^([ugo]*|[a]?)([+\-=])([ugo]|[rwx]*)$")
if p.match(sym):
symdesc.append(sym)
else:
valid = False
if valid:
return symdesc
else:
return False

Expand Down

0 comments on commit 4955e30

Please sign in to comment.