@@ -2439,9 +2439,13 @@ def _list_outputs(self):
2439
2439
isdefined (self .inputs .field_template ) and \
2440
2440
key in self .inputs .field_template :
2441
2441
template = self .inputs .field_template [key ]
2442
+
2442
2443
if not args :
2444
+ # Connect over SSH
2443
2445
client = self ._get_ssh_client ()
2444
2446
sftp = client .open_sftp ()
2447
+
2448
+ # Get the files in the base dir, and filter for desired files
2445
2449
sftp .chdir (self .inputs .base_directory )
2446
2450
filelist = sftp .listdir ()
2447
2451
if self .inputs .template_expression == 'fnmatch' :
@@ -2451,20 +2455,26 @@ def _list_outputs(self):
2451
2455
filelist = list (filter (regexp .match , filelist ))
2452
2456
else :
2453
2457
raise ValueError ('template_expression value invalid' )
2458
+
2454
2459
if len (filelist ) == 0 :
2460
+ # no files
2455
2461
msg = 'Output key: %s Template: %s returned no files' % (
2456
2462
key , template )
2457
2463
if self .inputs .raise_on_empty :
2458
2464
raise IOError (msg )
2459
2465
else :
2460
2466
warn (msg )
2461
2467
else :
2468
+ # found files, sort and save to outputs
2462
2469
if self .inputs .sort_filelist :
2463
2470
filelist = human_order_sorted (filelist )
2464
2471
outputs [key ] = list_to_filename (filelist )
2472
+
2473
+ # actually download the files, if desired
2465
2474
if self .inputs .download_files :
2466
2475
for f in filelist :
2467
2476
sftp .get (f , f )
2477
+
2468
2478
for argnum , arglist in enumerate (args ):
2469
2479
maxlen = 1
2470
2480
for arg in arglist :
@@ -2498,9 +2508,13 @@ def _list_outputs(self):
2498
2508
e .message +
2499
2509
": Template %s failed to convert with args %s"
2500
2510
% (template , str (tuple (argtuple ))))
2511
+
2512
+ # Connect over SSH
2501
2513
client = self ._get_ssh_client ()
2502
2514
sftp = client .open_sftp ()
2503
2515
sftp .chdir (self .inputs .base_directory )
2516
+
2517
+ # Get all files in the dir, and filter for desired files
2504
2518
filledtemplate_dir = os .path .dirname (filledtemplate )
2505
2519
filledtemplate_base = os .path .basename (filledtemplate )
2506
2520
filelist = sftp .listdir (filledtemplate_dir )
@@ -2512,18 +2526,24 @@ def _list_outputs(self):
2512
2526
outfiles = list (filter (regexp .match , filelist ))
2513
2527
else :
2514
2528
raise ValueError ('template_expression value invalid' )
2529
+
2515
2530
if len (outfiles ) == 0 :
2516
2531
msg = 'Output key: %s Template: %s returned no files' % (
2517
2532
key , filledtemplate )
2533
+
2534
+ # no files
2518
2535
if self .inputs .raise_on_empty :
2519
2536
raise IOError (msg )
2520
2537
else :
2521
2538
warn (msg )
2522
2539
outputs [key ].append (None )
2523
2540
else :
2541
+ # found files, sort and save to outputs
2524
2542
if self .inputs .sort_filelist :
2525
2543
outfiles = human_order_sorted (outfiles )
2526
2544
outputs [key ].append (list_to_filename (outfiles ))
2545
+
2546
+ # actually download the files, if desired
2527
2547
if self .inputs .download_files :
2528
2548
for f in outfiles :
2529
2549
try :
@@ -2532,10 +2552,16 @@ def _list_outputs(self):
2532
2552
except IOError :
2533
2553
iflogger .info ('remote file %s not found' ,
2534
2554
f )
2555
+
2556
+ # disclude where there was any invalid matches
2535
2557
if any ([val is None for val in outputs [key ]]):
2536
2558
outputs [key ] = []
2559
+
2560
+ # no outputs is None, not empty list
2537
2561
if len (outputs [key ]) == 0 :
2538
2562
outputs [key ] = None
2563
+
2564
+ # one output is the item, not a list
2539
2565
elif len (outputs [key ]) == 1 :
2540
2566
outputs [key ] = outputs [key ][0 ]
2541
2567
0 commit comments