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 ,
@@ -2321,12 +2324,12 @@ def _get_files_over_ssh(self, template):
2321
2324
# Get all files in the dir, and filter for desired files
2322
2325
template_dir = os .path .dirname (template )
2323
2326
template_base = os .path .basename (template )
2324
- filelist = sftp .listdir (template_dir )
2327
+ every_file_in_dir = sftp .listdir (template_dir )
2325
2328
if self .inputs .template_expression == 'fnmatch' :
2326
- outfiles = fnmatch .filter (filelist , template_base )
2329
+ outfiles = fnmatch .filter (every_file_in_dir , template_base )
2327
2330
elif self .inputs .template_expression == 'regexp' :
2328
2331
regexp = re .compile (template_base )
2329
- outfiles = list (filter (regexp .match , filelist ))
2332
+ outfiles = list (filter (regexp .match , every_file_in_dir ))
2330
2333
else :
2331
2334
raise ValueError ('template_expression value invalid' )
2332
2335
@@ -2348,7 +2351,18 @@ def _get_files_over_ssh(self, template):
2348
2351
2349
2352
# actually download the files, if desired
2350
2353
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 :
2352
2366
try :
2353
2367
sftp .get (os .path .join (template_dir , f ), f )
2354
2368
except IOError :
0 commit comments