29
29
import shutil
30
30
import subprocess
31
31
import re
32
+ import copy
32
33
import tempfile
33
34
from warnings import warn
34
35
35
36
import sqlite3
36
37
37
38
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 )
39
42
from ..utils .misc import human_order_sorted , str2bool
40
43
from .base import (
41
44
TraitedSpec , traits , Str , File , Directory , BaseInterface , InputMultiPath ,
@@ -2319,12 +2322,12 @@ def _get_files_over_ssh(self, template):
2319
2322
# Get all files in the dir, and filter for desired files
2320
2323
template_dir = os .path .dirname (template )
2321
2324
template_base = os .path .basename (template )
2322
- filelist = sftp .listdir (template_dir )
2325
+ every_file_in_dir = sftp .listdir (template_dir )
2323
2326
if self .inputs .template_expression == 'fnmatch' :
2324
- outfiles = fnmatch .filter (filelist , template_base )
2327
+ outfiles = fnmatch .filter (every_file_in_dir , template_base )
2325
2328
elif self .inputs .template_expression == 'regexp' :
2326
2329
regexp = re .compile (template_base )
2327
- outfiles = list (filter (regexp .match , filelist ))
2330
+ outfiles = list (filter (regexp .match , every_file_in_dir ))
2328
2331
else :
2329
2332
raise ValueError ('template_expression value invalid' )
2330
2333
@@ -2346,7 +2349,18 @@ def _get_files_over_ssh(self, template):
2346
2349
2347
2350
# actually download the files, if desired
2348
2351
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 :
2350
2364
try :
2351
2365
sftp .get (os .path .join (template_dir , f ), f )
2352
2366
except IOError :
0 commit comments