Skip to content

Commit c9c92ef

Browse files
committed
Added handling of DataSink to save to a local directory if it cant access S3
1 parent 42f0b1b commit c9c92ef

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

nipype/interfaces/io.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,7 @@ def _check_s3_base_dir(self):
400400
except Exception as exc:
401401
err_msg = 'Unable to access S3 bucket. Error:\n%s. Exiting...'\
402402
% exc
403-
print err_msg
404-
sys.exit()
403+
raise Exception(err_msg)
405404
# Bucket access was a success, set flag
406405
s3_flag = True
407406
# Otherwise it's just a normal datasink
@@ -599,7 +598,18 @@ def _list_outputs(self):
599598
outdir = '.'
600599

601600
# Check if base directory reflects S3-bucket upload
602-
s3_flag = self._check_s3_base_dir()
601+
try:
602+
s3_flag = self._check_s3_base_dir()
603+
# If encountering an exception during bucket access, set output
604+
# base directory to a local folder
605+
except Exception as exc:
606+
local_out_exception = os.path.join(os.path.expanduser('~'),
607+
'data_output')
608+
iflogger.info('Access to S3 failed! Storing outputs locally at: '\
609+
'%s\nError: %s' %(local_out_exception, exc))
610+
self.inputs.base_directory = local_out_exception
611+
612+
# If not accessing S3, just set outdir to local absolute path
603613
if not s3_flag:
604614
outdir = os.path.abspath(outdir)
605615

0 commit comments

Comments
 (0)