Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 'verbose' in IOHandler #12

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/pyremotedata/implicit_mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,8 @@ def __enter__(self) -> "IOHandler":
# Print local directory:
# if the local directory is not specified in the config,
# it is a temporary directory, so it is nice to know where it is located
print(f"Local directory: {self.lpwd()}")
if self.verbose:
print(f"Local directory: {self.lpwd()}")

# Return self
return self
Expand All @@ -682,8 +683,9 @@ def start(self) -> None:
Very useful for interactive use, but shouldn't be used in scripts, using a context manager is safer and does the same.
"""
self.__enter__()
print("IOHandler.start() is unsafe. Use IOHandler.__enter__() instead if possible.")
print("OBS: Remember to call IOHandler.stop() when you are done.")
if self.verbose:
print("IOHandler.start() is unsafe. Use IOHandler.__enter__() instead if possible.")
print("OBS: Remember to call IOHandler.stop() when you are done.")

def stop(self) -> None:
"""
Expand Down Expand Up @@ -834,7 +836,7 @@ def get_file_index(self, skip: int=0, nmax: Union[int, None]=None, override: boo
raise ValueError("override cannot be 'True' if store is 'False'!")
# Check if file index exists
file_index_exists = self.execute_command('glob -f --exist *folder_index.txt && echo "YES" || echo "NO"') == "YES"
if not file_index_exists:
if not file_index_exists and self.verbose:
print(f"Folder index does not exist in {self.pwd()}")
# If override is True, delete the file index if it exists
if override and file_index_exists:
Expand All @@ -844,7 +846,8 @@ def get_file_index(self, skip: int=0, nmax: Union[int, None]=None, override: boo
file_index_exists = False
# If the file index does not exist, create it
if not file_index_exists:
print("Creating folder index...")
if self.verbose:
print("Creating folder index...")
# Traverse the remote directory and write the file index to a file
files = self.ls(recursive=True, use_cache=False)
local_index_path = f"{self.lpwd()}folder_index.txt"
Expand Down Expand Up @@ -925,9 +928,11 @@ def clean(self):
# Ask for confirmation
confirmation = input(f"Are you sure you want to delete all files in the current directory {self.lpwd()}? (y/n)")
if confirmation.lower() != "y":
print("Aborted")
if self.verbose:
print("Aborted")
return
print("Cleaning up...")
if self.verbose:
print("Cleaning up...")
for path in os.listdir(self.lpwd()):
if os.path.isfile(path):
os.remove(path)
Expand Down Expand Up @@ -961,7 +966,8 @@ def clean_last(self):
else:
raise RuntimeError(f"Unknown last type {self.last_type}")
if confirmation.lower() != "y":
print("Aborted")
if self.verbose:
print("Aborted")
return

if self.original_local_dir == self.lpwd():
Expand Down