Skip to content

Commit 95a6d25

Browse files
committed
ENH: SSHDataGrabber also downloads related files
1 parent a866a78 commit 95a6d25

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

nipype/interfaces/io.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@
2929
import shutil
3030
import subprocess
3131
import re
32+
import copy
3233
import tempfile
3334
from warnings import warn
3435

3536
import sqlite3
3637

3738
from .. import config, logging
38-
from ..utils.filemanip import copyfile, list_to_filename, filename_to_list
39+
from ..utils.filemanip import (
40+
copyfile, list_to_filename, filename_to_list,
41+
get_related_files, related_filetype_sets)
3942
from ..utils.misc import human_order_sorted, str2bool
4043
from .base import (
4144
TraitedSpec, traits, Str, File, Directory, BaseInterface, InputMultiPath,
@@ -2319,12 +2322,12 @@ def _get_files_over_ssh(self, template):
23192322
# Get all files in the dir, and filter for desired files
23202323
template_dir = os.path.dirname(template)
23212324
template_base = os.path.basename(template)
2322-
filelist = sftp.listdir(template_dir)
2325+
every_file_in_dir = sftp.listdir(template_dir)
23232326
if self.inputs.template_expression == 'fnmatch':
2324-
outfiles = fnmatch.filter(filelist, template_base)
2327+
outfiles = fnmatch.filter(every_file_in_dir, template_base)
23252328
elif self.inputs.template_expression == 'regexp':
23262329
regexp = re.compile(template_base)
2327-
outfiles = list(filter(regexp.match, filelist))
2330+
outfiles = list(filter(regexp.match, every_file_in_dir))
23282331
else:
23292332
raise ValueError('template_expression value invalid')
23302333

@@ -2346,7 +2349,18 @@ def _get_files_over_ssh(self, template):
23462349

23472350
# actually download the files, if desired
23482351
if self.inputs.download_files:
2349-
for f in outfiles:
2352+
files_to_download = copy.copy(outfiles) # make sure new list!
2353+
2354+
# check to see if there are any related files to download
2355+
for file_to_download in files_to_download:
2356+
related_to_current = get_related_files(
2357+
file_to_download, include_this_file=False)
2358+
existing_related_not_downloading = [
2359+
f for f in related_to_current
2360+
if f in every_file_in_dir and f not in files_to_download]
2361+
files_to_download.extend(existing_related_not_downloading)
2362+
2363+
for f in files_to_download:
23502364
try:
23512365
sftp.get(os.path.join(template_dir, f), f)
23522366
except IOError:

0 commit comments

Comments
 (0)