Skip to content

Commit 69c948a

Browse files
committed
ENH: SSHDataGrabber also downloads related files
1 parent a1b9905 commit 69c948a

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,
@@ -2321,12 +2324,12 @@ def _get_files_over_ssh(self, template):
23212324
# Get all files in the dir, and filter for desired files
23222325
template_dir = os.path.dirname(template)
23232326
template_base = os.path.basename(template)
2324-
filelist = sftp.listdir(template_dir)
2327+
every_file_in_dir = sftp.listdir(template_dir)
23252328
if self.inputs.template_expression == 'fnmatch':
2326-
outfiles = fnmatch.filter(filelist, template_base)
2329+
outfiles = fnmatch.filter(every_file_in_dir, template_base)
23272330
elif self.inputs.template_expression == 'regexp':
23282331
regexp = re.compile(template_base)
2329-
outfiles = list(filter(regexp.match, filelist))
2332+
outfiles = list(filter(regexp.match, every_file_in_dir))
23302333
else:
23312334
raise ValueError('template_expression value invalid')
23322335

@@ -2348,7 +2351,18 @@ def _get_files_over_ssh(self, template):
23482351

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

0 commit comments

Comments
 (0)