mirror of
https://github.com/MAGICGrants/truenas-apps.git
synced 2026-01-09 20:47:58 -05:00
fix identation
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
from . import utils
|
||||
import textwrap
|
||||
import re
|
||||
|
||||
RE_ID = re.compile(r"^[0-9]+$")
|
||||
@@ -7,22 +6,20 @@ RE_MODE = re.compile(r"^(0o)?([0-7]{3})$")
|
||||
|
||||
|
||||
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())
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user