Skip to content

Commit

Permalink
Merge pull request #258 from pyiron/delete_file_on_remote
Browse files Browse the repository at this point in the history
Add delete_file_on_remote option to transfer_file()
  • Loading branch information
jan-janssen authored Feb 3, 2024
2 parents 5452967 + 13c4c6d commit 9051667
Show file tree
Hide file tree
Showing 4 changed files with 14 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 @@ -161,7 +161,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 @@ -172,7 +172,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
14 changes: 10 additions & 4 deletions pysqa/queueadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,22 @@ 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 9051667

Please sign in to comment.