Don't use ternary if statements. Fixes #8784
This commit is contained in:
parent
f8a30faeee
commit
2b307985bc
1 changed files with 17 additions and 3 deletions
|
@ -608,12 +608,24 @@ class AnsibleModule(object):
|
||||||
|
|
||||||
# Permission bits constants documented at:
|
# Permission bits constants documented at:
|
||||||
# http://docs.python.org/2/library/stat.html#stat.S_ISUID
|
# http://docs.python.org/2/library/stat.html#stat.S_ISUID
|
||||||
|
if apply_X_permission:
|
||||||
|
X_perms = {
|
||||||
|
'u': {'X': stat.S_IXUSR},
|
||||||
|
'g': {'X': stat.S_IXGRP},
|
||||||
|
'o': {'X': stat.S_IXOTH}
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
X_perms = {
|
||||||
|
'u': {'X': 0},
|
||||||
|
'g': {'X': 0},
|
||||||
|
'o': {'X': 0}
|
||||||
|
}
|
||||||
|
|
||||||
user_perms_to_modes = {
|
user_perms_to_modes = {
|
||||||
'u': {
|
'u': {
|
||||||
'r': stat.S_IRUSR,
|
'r': stat.S_IRUSR,
|
||||||
'w': stat.S_IWUSR,
|
'w': stat.S_IWUSR,
|
||||||
'x': stat.S_IXUSR,
|
'x': stat.S_IXUSR,
|
||||||
'X': stat.S_IXUSR if apply_X_permission else 0,
|
|
||||||
's': stat.S_ISUID,
|
's': stat.S_ISUID,
|
||||||
't': 0,
|
't': 0,
|
||||||
'u': prev_mode & stat.S_IRWXU,
|
'u': prev_mode & stat.S_IRWXU,
|
||||||
|
@ -623,7 +635,6 @@ class AnsibleModule(object):
|
||||||
'r': stat.S_IRGRP,
|
'r': stat.S_IRGRP,
|
||||||
'w': stat.S_IWGRP,
|
'w': stat.S_IWGRP,
|
||||||
'x': stat.S_IXGRP,
|
'x': stat.S_IXGRP,
|
||||||
'X': stat.S_IXGRP if apply_X_permission else 0,
|
|
||||||
's': stat.S_ISGID,
|
's': stat.S_ISGID,
|
||||||
't': 0,
|
't': 0,
|
||||||
'u': (prev_mode & stat.S_IRWXU) >> 3,
|
'u': (prev_mode & stat.S_IRWXU) >> 3,
|
||||||
|
@ -633,7 +644,6 @@ class AnsibleModule(object):
|
||||||
'r': stat.S_IROTH,
|
'r': stat.S_IROTH,
|
||||||
'w': stat.S_IWOTH,
|
'w': stat.S_IWOTH,
|
||||||
'x': stat.S_IXOTH,
|
'x': stat.S_IXOTH,
|
||||||
'X': stat.S_IXOTH if apply_X_permission else 0,
|
|
||||||
's': 0,
|
's': 0,
|
||||||
't': stat.S_ISVTX,
|
't': stat.S_ISVTX,
|
||||||
'u': (prev_mode & stat.S_IRWXU) >> 6,
|
'u': (prev_mode & stat.S_IRWXU) >> 6,
|
||||||
|
@ -641,6 +651,10 @@ class AnsibleModule(object):
|
||||||
'o': prev_mode & stat.S_IRWXO }
|
'o': prev_mode & stat.S_IRWXO }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Insert X_perms into user_perms_to_modes
|
||||||
|
for key, value in X_perms.items():
|
||||||
|
user_perms_to_modes[key].update(value)
|
||||||
|
|
||||||
or_reduce = lambda mode, perm: mode | user_perms_to_modes[user][perm]
|
or_reduce = lambda mode, perm: mode | user_perms_to_modes[user][perm]
|
||||||
return reduce(or_reduce, perms, 0)
|
return reduce(or_reduce, perms, 0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue