Skip to content

Commit

Permalink
Add delete_file_on_remote option to transfer_file()
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed Feb 3, 2024
1 parent 159fcd0 commit ba23958
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pysqa/ext/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get_job_from_remote(self, working_directory):
if self._ssh_delete_file_on_remote:
self._execute_remote_command(command="rm -r " + remote_working_directory)

def transfer_file(self, file, transfer_back=False):
def transfer_file(self, file, transfer_back=False, delete_file_on_remote=False):
working_directory = os.path.abspath(os.path.expanduser(file))
remote_working_directory = self._get_remote_working_dir(
working_directory=working_directory
Expand All @@ -152,7 +152,7 @@ def transfer_file(self, file, transfer_back=False):
sftp=None,
transfer_back=transfer_back,
)
if self._ssh_delete_file_on_remote and transfer_back:
if self._ssh_delete_file_on_remote and transfer_back and delete_file_on_remote:
self._execute_remote_command(command="rm " + remote_working_directory)

def __del__(self):
Expand Down
12 changes: 8 additions & 4 deletions pysqa/queueadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,20 @@ def get_job_from_remote(self, working_directory):
"""
self._adapter.get_job_from_remote(working_directory=working_directory)

def transfer_file_to_remote(self, file, transfer_back=False):
def transfer_file_to_remote(self, file, transfer_back=False, delete_file_on_remote=False):
"""
Transfer file from remote host to local host
Args:
file (str):
transfer_back (bool):
Returns:
str:
delete_file_on_remote (bool):
"""
self._adapter.transfer_file(file=file, transfer_back=transfer_back)
self._adapter.transfer_file(
file=file,
transfer_back=transfer_back,
delete_file_on_remote=delete_file_on_remote
)

def convert_path_to_remote(self, path):
"""
Expand Down
2 changes: 1 addition & 1 deletion pysqa/utils/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def get_job_from_remote(self, working_directory):
def convert_path_to_remote(self, path):
raise NotImplementedError

def transfer_file(self, file, transfer_back=False):
def transfer_file(self, file, transfer_back=False, delete_file_on_remote=False):
raise NotImplementedError

def check_queue_parameters(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def execute_command(
slurm_tmp._adapter.convert_path_to_remote(path="test")

with self.assertRaises(NotImplementedError):
slurm_tmp._adapter.transfer_file(file="test", transfer_back=False)
slurm_tmp._adapter.transfer_file(file="test", transfer_back=False, delete_file_on_remote=False)

with self.assertRaises(NotImplementedError):
slurm_tmp._adapter.get_job_from_remote(working_directory=".")

0 comments on commit ba23958

Please sign in to comment.