Skip to content

Commit 9708216

Browse files
committed
Comment existing SSHDataGrabber._list_outputs() to make interpretable
1 parent 04d0159 commit 9708216

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

nipype/interfaces/io.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,9 +2439,13 @@ def _list_outputs(self):
24392439
isdefined(self.inputs.field_template) and \
24402440
key in self.inputs.field_template:
24412441
template = self.inputs.field_template[key]
2442+
24422443
if not args:
2444+
# Connect over SSH
24432445
client = self._get_ssh_client()
24442446
sftp = client.open_sftp()
2447+
2448+
# Get the files in the base dir, and filter for desired files
24452449
sftp.chdir(self.inputs.base_directory)
24462450
filelist = sftp.listdir()
24472451
if self.inputs.template_expression == 'fnmatch':
@@ -2451,20 +2455,26 @@ def _list_outputs(self):
24512455
filelist = list(filter(regexp.match, filelist))
24522456
else:
24532457
raise ValueError('template_expression value invalid')
2458+
24542459
if len(filelist) == 0:
2460+
# no files
24552461
msg = 'Output key: %s Template: %s returned no files' % (
24562462
key, template)
24572463
if self.inputs.raise_on_empty:
24582464
raise IOError(msg)
24592465
else:
24602466
warn(msg)
24612467
else:
2468+
# found files, sort and save to outputs
24622469
if self.inputs.sort_filelist:
24632470
filelist = human_order_sorted(filelist)
24642471
outputs[key] = list_to_filename(filelist)
2472+
2473+
# actually download the files, if desired
24652474
if self.inputs.download_files:
24662475
for f in filelist:
24672476
sftp.get(f, f)
2477+
24682478
for argnum, arglist in enumerate(args):
24692479
maxlen = 1
24702480
for arg in arglist:
@@ -2498,9 +2508,13 @@ def _list_outputs(self):
24982508
e.message +
24992509
": Template %s failed to convert with args %s"
25002510
% (template, str(tuple(argtuple))))
2511+
2512+
# Connect over SSH
25012513
client = self._get_ssh_client()
25022514
sftp = client.open_sftp()
25032515
sftp.chdir(self.inputs.base_directory)
2516+
2517+
# Get all files in the dir, and filter for desired files
25042518
filledtemplate_dir = os.path.dirname(filledtemplate)
25052519
filledtemplate_base = os.path.basename(filledtemplate)
25062520
filelist = sftp.listdir(filledtemplate_dir)
@@ -2512,18 +2526,24 @@ def _list_outputs(self):
25122526
outfiles = list(filter(regexp.match, filelist))
25132527
else:
25142528
raise ValueError('template_expression value invalid')
2529+
25152530
if len(outfiles) == 0:
25162531
msg = 'Output key: %s Template: %s returned no files' % (
25172532
key, filledtemplate)
2533+
2534+
# no files
25182535
if self.inputs.raise_on_empty:
25192536
raise IOError(msg)
25202537
else:
25212538
warn(msg)
25222539
outputs[key].append(None)
25232540
else:
2541+
# found files, sort and save to outputs
25242542
if self.inputs.sort_filelist:
25252543
outfiles = human_order_sorted(outfiles)
25262544
outputs[key].append(list_to_filename(outfiles))
2545+
2546+
# actually download the files, if desired
25272547
if self.inputs.download_files:
25282548
for f in outfiles:
25292549
try:
@@ -2532,10 +2552,16 @@ def _list_outputs(self):
25322552
except IOError:
25332553
iflogger.info('remote file %s not found',
25342554
f)
2555+
2556+
# disclude where there was any invalid matches
25352557
if any([val is None for val in outputs[key]]):
25362558
outputs[key] = []
2559+
2560+
# no outputs is None, not empty list
25372561
if len(outputs[key]) == 0:
25382562
outputs[key] = None
2563+
2564+
# one output is the item, not a list
25392565
elif len(outputs[key]) == 1:
25402566
outputs[key] = outputs[key][0]
25412567

0 commit comments

Comments
 (0)