31
31
import shutil
32
32
import subprocess
33
33
import re
34
+ import copy
34
35
import tempfile
35
36
from os .path import join , dirname
36
37
from warnings import warn
37
38
38
39
import sqlite3
39
40
40
41
from .. import config , logging
41
- from ..utils .filemanip import copyfile , list_to_filename , filename_to_list
42
+ from ..utils .filemanip import (
43
+ copyfile , list_to_filename , filename_to_list ,
44
+ get_related_files , related_filetype_sets )
42
45
from ..utils .misc import human_order_sorted , str2bool
43
46
from .base import (
44
47
TraitedSpec , traits , Str , File , Directory , BaseInterface , InputMultiPath ,
@@ -2422,12 +2425,12 @@ def _get_files_over_ssh(self, template):
2422
2425
# Get all files in the dir, and filter for desired files
2423
2426
template_dir = os .path .dirname (template )
2424
2427
template_base = os .path .basename (template )
2425
- filelist = sftp .listdir (template_dir )
2428
+ every_file_in_dir = sftp .listdir (template_dir )
2426
2429
if self .inputs .template_expression == 'fnmatch' :
2427
- outfiles = fnmatch .filter (filelist , template_base )
2430
+ outfiles = fnmatch .filter (every_file_in_dir , template_base )
2428
2431
elif self .inputs .template_expression == 'regexp' :
2429
2432
regexp = re .compile (template_base )
2430
- outfiles = list (filter (regexp .match , filelist ))
2433
+ outfiles = list (filter (regexp .match , every_file_in_dir ))
2431
2434
else :
2432
2435
raise ValueError ('template_expression value invalid' )
2433
2436
@@ -2450,7 +2453,18 @@ def _get_files_over_ssh(self, template):
2450
2453
2451
2454
# actually download the files, if desired
2452
2455
if self .inputs .download_files :
2453
- for f in outfiles :
2456
+ files_to_download = copy .copy (outfiles ) # make sure new list!
2457
+
2458
+ # check to see if there are any related files to download
2459
+ for file_to_download in files_to_download :
2460
+ related_to_current = get_related_files (
2461
+ file_to_download , include_this_file = False )
2462
+ existing_related_not_downloading = [
2463
+ f for f in related_to_current
2464
+ if f in every_file_in_dir and f not in files_to_download ]
2465
+ files_to_download .extend (existing_related_not_downloading )
2466
+
2467
+ for f in files_to_download :
2454
2468
try :
2455
2469
sftp .get (os .path .join (template_dir , f ), f )
2456
2470
except IOError :
0 commit comments