mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add comments to move_item_file_or_dir.
This commit is contained in:
parent
85b930d67a
commit
770c648d51
@ -395,17 +395,35 @@ class FileHelpers:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def move_item_file_or_dir(old_dir, new_dir, item) -> None:
|
def move_item_file_or_dir(old_dir, new_dir, item) -> None:
|
||||||
|
"""
|
||||||
|
Move item to new location if it is either a file or a dir. Will raise
|
||||||
|
shutil.Error for any errors encountered.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
old_dir: Old location.
|
||||||
|
new_dir: New location.
|
||||||
|
item: File or directory name.
|
||||||
|
|
||||||
|
Returns: None
|
||||||
|
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
|
# Check if source item is a directory or a file.
|
||||||
if os.path.isdir(os.path.join(old_dir, item)):
|
if os.path.isdir(os.path.join(old_dir, item)):
|
||||||
|
# Source item is a directory
|
||||||
FileHelpers.move_dir_exist(
|
FileHelpers.move_dir_exist(
|
||||||
os.path.join(old_dir, item),
|
os.path.join(old_dir, item),
|
||||||
os.path.join(new_dir, item),
|
os.path.join(new_dir, item),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
# Source item is a file.
|
||||||
FileHelpers.move_file(
|
FileHelpers.move_file(
|
||||||
os.path.join(old_dir, item),
|
os.path.join(old_dir, item),
|
||||||
os.path.join(new_dir, item),
|
os.path.join(new_dir, item),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Error raised by shutil if an error is encountered. Raising the same error if
|
||||||
|
# encountered.
|
||||||
except shutil.Error as why:
|
except shutil.Error as why:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Error moving {old_dir} to {new_dir} with information: {why}"
|
f"Error moving {old_dir} to {new_dir} with information: {why}"
|
||||||
|
Loading…
Reference in New Issue
Block a user