Skip to content

Commit

Permalink
special case handling in the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
jrybicki-jsc committed Dec 22, 2023
1 parent c9f7b33 commit ee4e247
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 11 additions & 5 deletions ssh2ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pendulum

from decors import get_connection
from utils import copy_streams, RFSC, walk_dir
from utils import copy_streams, RFSC, file_exist, is_dir, walk_dir



Expand Down Expand Up @@ -52,14 +52,20 @@ def copy(**context):

source_ssh_hook = get_connection(conn_id=s_con_id, params=s_params)
target_ssh_hook = get_connection(conn_id=t_con_id, params=t_params)
target_client = target_ssh_hook.get_conn().open_sftp()
target_conn = target_ssh_hook.get_conn()
target_client = target_conn.open_sftp()

sftp_client = source_ssh_hook.get_conn().open_sftp()
sclient = RFSC(sftp_client)


target_conn = target_ssh_hook.get_conn()

mappings = list(walk_dir(client=sclient, path=s_params["path"], prefix=""))
if file_exist(sftp_client, s_params['path']) and not is_dir(sftp_client, s_params['path']):
print("Special case it is a file")
mappings=[s_params['path']]
s_params['path']=os.path.dirname(s_params['path'])
else:
mappings = list(walk_dir(client=sclient, path=s_params["path"], prefix=""))

for fname in mappings:
target_name = fname.replace(s_params["path"], t_params["path"])
print("Processing", fname, "-->", target_name)
Expand Down
5 changes: 0 additions & 5 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,6 @@ def __init__(self, client, **kwargs):
self.client = client

def list(self, path, get_info=True):
if file_exist(self.client, path) and not is_dir(self.client, path):
print("Special case it is a file")
if not get_info:
return [path]
return [{"path": path, "isdir": False}]

if not get_info:
return [el.filename for el in self.client.listdir_attr(path)]
Expand Down

0 comments on commit ee4e247

Please sign in to comment.