Skip to content

Commit 284feb8

Browse files
committed
still working, needs a bit more tidying up.
1 parent df2eebc commit 284feb8

3 files changed

Lines changed: 208 additions & 205 deletions

File tree

datashuttle/utils/data_transfer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def build_a_list_of_all_files_and_folders_to_transfer(self) -> List[str]:
8383
self.update_list_with_non_ses_sub_level_folders(
8484
extra_folder_names, extra_filenames, sub
8585
)
86-
8786
continue
8887

8988
# Datatype (sub and ses level) --------------------------------

tests/ssh_test_utils.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import builtins
22
import copy
3+
import stat
4+
5+
import paramiko
36

47
from datashuttle.utils import rclone, ssh
58

@@ -57,7 +60,7 @@ def setup_hostkeys(project):
5760
restore_mock_input(orig_builtin)
5861

5962
orig_getpass = copy.deepcopy(ssh.getpass.getpass)
60-
ssh.getpass.getpass = lambda _: "password"
63+
ssh.getpass.getpass = lambda _: "password" # type: ignore
6164

6265
ssh.setup_ssh_key(project.cfg, log=False)
6366
ssh.getpass.getpass = orig_getpass
@@ -81,3 +84,37 @@ def build_docker_image(project):
8184
central_host_id="localhost",
8285
central_host_username="sshuser",
8386
)
87+
88+
89+
def sftp_recursive_file_search(sftp, path_, all_filenames):
90+
try:
91+
sftp.stat(path_)
92+
except FileNotFoundError:
93+
return
94+
95+
for file_or_folder in sftp.listdir_attr(path_):
96+
if stat.S_ISDIR(file_or_folder.st_mode):
97+
sftp_recursive_file_search(
98+
sftp,
99+
path_ + "/" + file_or_folder.filename,
100+
all_filenames,
101+
)
102+
else:
103+
all_filenames.append(path_ + "/" + file_or_folder.filename)
104+
105+
106+
def recursive_search_central(project):
107+
""" """
108+
with paramiko.SSHClient() as client:
109+
ssh.connect_client(client, project.cfg)
110+
111+
sftp = client.open_sftp()
112+
113+
all_filenames = []
114+
115+
sftp_recursive_file_search(
116+
sftp,
117+
(project.cfg["central_path"] / "rawdata").as_posix(),
118+
all_filenames,
119+
)
120+
return all_filenames

0 commit comments

Comments
 (0)