Functions

Remove superfluous "acl_" prefix from function names, the module
is already called "acl".
Replace hardcoded test path with functions to parse a given file.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2024-09-16 04:10:02 +02:00
parent d48c773cb4
commit 40f64775ab
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57

View File

@ -10,11 +10,6 @@ You may obtain copies of the Licence in any of the official languages at https:/
import posix1e
myacl = posix1e.ACL(file='/tmp/testacl')
print(myacl)
myentries = list(myacl)
DEFAULT_ENTRIES = [
'u::rw-',
'g::r--',
@ -37,12 +32,14 @@ DEFAULT_ENTRYTYPES = [
MAX_PERMBITS = 3
def acl_reduce_entries(acl):
def reduce_entries(acl):
entries = acl.to_any_text().decode().split()
entries = [entry for entry in entries if entry not in DEFAULT_ENTRIES]
return entries
def acl_parse_permission(strpermission):
def parse_permission(strpermission):
if len(strpermission) != MAX_PERMBITS:
return ValueError('Invalid permission')
@ -65,7 +62,8 @@ def acl_parse_permission(strpermission):
return outmap
def acl_parse_entry(strentry):
def parse_entry(strentry):
if not strentry:
raise ValueError('Got empty string')
@ -84,16 +82,29 @@ def acl_parse_entry(strentry):
return {
entrytype: {
entryvalue: acl_parse_permission(permissions),
entryvalue: parse_permission(permissions),
},
}
def acl_parse_entries(acl):
def parse_entries(acl):
outmap = {
group: DEFAULT_PERMISSIONS for group in DEFAULT_ENTRYTYPES
}
for entry in acl:
outmap.update(acl_parse_entry(entry))
outmap.update(parse_entry(entry))
return outmap
def aclfromfile(path):
return posix1e.ACL(file=path)
def entriesfromfile(path):
return reduce_entries(aclfromfile(path))
def parsefromfile(path):
return parse_entries(reduce_entries(aclfromfile(path)))