Skip to content

Commit 9b814da

Browse files
committed
improve comments, var naming, remove unused option
with_val is never set to false Signed-off-by: Zen <[email protected]>
1 parent a3cc9be commit 9b814da

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/ugrd/fs/mounts.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "desultory"
2-
__version__ = "7.1.2"
2+
__version__ = "7.1.3"
33

44
from pathlib import Path
55
from re import search
@@ -130,13 +130,16 @@ def _get_mount_dev_fs_type(self, device: str, raise_exception=True) -> str:
130130
self.logger.debug("No mount found for device: %s" % device)
131131

132132

133-
def _get_mount_source_type(self, mount: dict, with_val=False) -> str:
134-
"""Gets the source from the mount config."""
133+
def _get_mount_source(self, mount: dict) -> str:
134+
"""Gets the source from the mount config.
135+
Uses the order of SOURCE_TYPES to determine the source type.
136+
uuid, partuuid, label, path.
137+
138+
Returns the source type and value if found, otherwise raises a ValueError.
139+
"""
135140
for source_type in SOURCE_TYPES:
136141
if source_type in mount:
137-
if with_val:
138-
return source_type, mount[source_type]
139-
return source_type
142+
return source_type, mount[source_type]
140143
raise ValueError("No source type found in mount: %s" % mount)
141144

142145

@@ -249,8 +252,8 @@ def _get_mount_str(self, mount: dict, pad=False, pad_size=44) -> str:
249252
"""returns the mount source string based on the config,
250253
the output string should work with fstab and mount commands.
251254
pad: pads the output string with spaces, defined by pad_size (44)."""
252-
mount_type, mount_name = _get_mount_source_type(self, mount, with_val=True)
253-
out_str = mount_name if mount_type == "path" else f"{mount_type.upper()}={mount_name}"
255+
mount_type, mount_val = _get_mount_source(self, mount)
256+
out_str = mount_val if mount_type == "path" else f"{mount_type.upper()}={mount_val}"
254257

255258
if pad:
256259
if len(out_str) > pad_size:
@@ -899,7 +902,7 @@ def _validate_host_mount(self, mount, destination_path=None) -> bool:
899902
if mount.get("base_mount"):
900903
return self.logger.debug("Skipping host mount validation for base mount: %s" % mount)
901904

902-
mount_type, mount_val = _get_mount_source_type(self, mount, with_val=True)
905+
mount_type, mount_val = _get_mount_source(self, mount)
903906
# If a destination path is passed, like for /, use that instead of the mount's destination
904907
destination_path = str(mount["destination"]) if destination_path is None else destination_path
905908

0 commit comments

Comments
 (0)