diff --git a/library/1.0.0/permissions.py b/library/1.0.0/permissions.py index 9a5663574c..a076c244f0 100644 --- a/library/1.0.0/permissions.py +++ b/library/1.0.0/permissions.py @@ -1,5 +1,4 @@ from . import utils -import textwrap import re RE_ID = re.compile(r"^[0-9]+$") @@ -7,22 +6,20 @@ def check_path(path): - out = f""" - if not pathlib.Path("{path}").exists(): - raise Exception(f"Path [{path}] does not exist") - """ - return textwrap.dedent(out) + return f""" +if not pathlib.Path("{path}").exists(): + raise Exception(f"Path [{path}] does not exist") +""" def check_empty(path, force=False): - out = f""" - if any(pathlib.Path("{path}").iterdir()): - if not {force}: - raise Exception( - f"Path [{path}] is not empty, skipping... Use [force=True] to override" - ) - """ - return textwrap.dedent(out) + return f""" +if any(pathlib.Path("{path}").iterdir()): + if not {force}: + raise Exception( + f"Path [{path}] is not empty, skipping... Use [force=True] to override" + ) +""" def chown(path, uid, gid, force=False): @@ -31,12 +28,13 @@ def chown(path, uid, gid, force=False): if not RE_ID.match(str(gid)): utils.throw_error(f"Group ID must be a number, but got [{gid}]") - out = f""" - {check_path(path)} - {check_empty(path, force)} - os.chown("{path}", {int(uid)}, {int(gid)}) - """ - return textwrap.dedent(out) + return f""" +{check_path(path)} +{check_empty(path, force)} +print(f"Changing owner of [{path}] to [{uid}:{gid}]") +os.chown("{path}", {int(uid)}, {int(gid)}) +print("New owner:", (os.stat("{path}").st_uid, os.stat("{path}").st_gid)) +""" def chmod(path, mode, force=False): @@ -45,9 +43,10 @@ def chmod(path, mode, force=False): f"Mode must be in octal format, but got [{mode}]. Example: 0o755 or 755" ) - out = f""" - {check_path(path)} - {check_empty(path, force)} - os.chmod("{path}", {int(mode, 8)}) - """ - return textwrap.dedent(out) + return f""" +{check_path(path)} +{check_empty(path, force)} +print(f"Changing mode of [{path}] to [{mode}]") +os.chmod("{path}", {int(mode, 8)}) +print("New mode:", (os.stat("{path}").st_mode).to_octal()) +"""