Skip to content

Commit

Permalink
add sftp recreation back
Browse files Browse the repository at this point in the history
  • Loading branch information
MehmedGIT committed Mar 6, 2024
1 parent 9cea952 commit 58eef90
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils/operandi_utils/hpc/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def get_and_unpack_slurm_workspace(self, ocrd_workspace_dir: str, workflow_job_d
self.log.info(f"Leaving get_and_unpack_slurm_workspace")

def mkdir_p(self, remotepath, mode=0o766):
self.recreate_sftp_if_required()
if remotepath == '/':
self.sftp_client.chdir('/') # absolute path so change directory to root
return False
Expand All @@ -224,6 +225,7 @@ def mkdir_p(self, remotepath, mode=0o766):
return True

def get_file(self, remote_src, local_dst):
self.recreate_sftp_if_required()
makedirs(name=Path(local_dst).parent.absolute(), exist_ok=True)
self.sftp_client.get(remotepath=remote_src, localpath=local_dst)

Expand All @@ -233,6 +235,7 @@ def get_dir(self, remote_src, local_dst, mode=0o766):
The remote source directory needs to exist.
All subdirectories in source are created under destination.
"""
self.recreate_sftp_if_required()
makedirs(name=local_dst, mode=mode, exist_ok=True)
for item in self.sftp_client.listdir(remote_src):
item_src = join(remote_src, item)
Expand All @@ -243,6 +246,7 @@ def get_dir(self, remote_src, local_dst, mode=0o766):
self.get_file(remote_src=item_src, local_dst=item_dst)

def put_file(self, local_src, remote_dst):
self.recreate_sftp_if_required()
self.mkdir_p(remotepath=str(Path(remote_dst).parent.absolute()))
self.sftp_client.put(localpath=local_src, remotepath=remote_dst)

Expand All @@ -252,6 +256,7 @@ def put_dir(self, local_src, remote_dst, mode=0o766):
The remote destination directory needs to exist.
All subdirectories in source are created under destination.
"""
self.recreate_sftp_if_required()
self.mkdir_p(remotepath=remote_dst, mode=mode)
for item in listdir(local_src):
item_src = join(local_src, item)
Expand Down

0 comments on commit 58eef90

Please sign in to comment.