@@ -209,7 +209,7 @@ class DataSinkInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
209
209
bucket = traits .Generic (mandatory = False ,
210
210
desc = 'Boto3 S3 bucket for manual override of bucket' )
211
211
# Set this if user wishes to have local copy of files as well
212
- local_dir = traits .Str (desc = 'Copy files locally as well as to S3 bucket' )
212
+ local_copy = traits .Str (desc = 'Copy files locally as well as to S3 bucket' )
213
213
214
214
# Set call-able inputs attributes
215
215
def __setattr__ (self , key , value ):
@@ -392,6 +392,10 @@ def _check_s3_base_dir(self):
392
392
s3_str = 's3://'
393
393
base_directory = self .inputs .base_directory
394
394
395
+ if not isdefined (base_directory ):
396
+ s3_flag = False
397
+ return s3_flag
398
+
395
399
# Explicitly lower-case the "s3"
396
400
if base_directory .lower ().startswith (s3_str ):
397
401
base_dir_sp = base_directory .split ('/' )
@@ -616,7 +620,7 @@ def _upload_to_s3(self, src, dst):
616
620
else :
617
621
iflogger .info ('Overwriting previous S3 file...' )
618
622
619
- except ClientError as exc :
623
+ except ClientError :
620
624
iflogger .info ('New file to S3' )
621
625
622
626
# Copy file up to S3 (either encrypted or not)
@@ -653,18 +657,21 @@ def _list_outputs(self):
653
657
# Check if base directory reflects S3 bucket upload
654
658
try :
655
659
s3_flag = self ._check_s3_base_dir ()
656
- s3dir = self .inputs .base_directory
657
- if isdefined (self .inputs .container ):
658
- s3dir = os .path .join (s3dir , self .inputs .container )
660
+ if s3_flag :
661
+ s3dir = self .inputs .base_directory
662
+ if isdefined (self .inputs .container ):
663
+ s3dir = os .path .join (s3dir , self .inputs .container )
664
+ else :
665
+ s3dir = '<N/A>'
659
666
# If encountering an exception during bucket access, set output
660
667
# base directory to a local folder
661
668
except Exception as exc :
669
+ s3dir = '<N/A>'
670
+ s3_flag = False
662
671
if not isdefined (self .inputs .local_copy ):
663
672
local_out_exception = os .path .join (os .path .expanduser ('~' ),
664
673
's3_datasink_' + self .bucket .name )
665
674
outdir = local_out_exception
666
- else :
667
- outdir = self .inputs .local_copy
668
675
# Log local copying directory
669
676
iflogger .info ('Access to S3 failed! Storing outputs locally at: ' \
670
677
'%s\n Error: %s' % (outdir , exc ))
@@ -673,8 +680,8 @@ def _list_outputs(self):
673
680
if isdefined (self .inputs .container ):
674
681
outdir = os .path .join (outdir , self .inputs .container )
675
682
676
- # If doing a localy output
677
- if not outdir . lower (). startswith ( 's3://' ) :
683
+ # If sinking to local folder
684
+ if outdir != s3dir :
678
685
outdir = os .path .abspath (outdir )
679
686
# Create the directory if it doesn't exist
680
687
if not os .path .exists (outdir ):
@@ -714,18 +721,19 @@ def _list_outputs(self):
714
721
if not os .path .isfile (src ):
715
722
src = os .path .join (src , '' )
716
723
dst = self ._get_dst (src )
724
+ if s3_flag :
725
+ s3dst = os .path .join (s3tempoutdir , dst )
726
+ s3dst = self ._substitute (s3dst )
717
727
dst = os .path .join (tempoutdir , dst )
718
- s3dst = os .path .join (s3tempoutdir , dst )
719
728
dst = self ._substitute (dst )
720
729
path , _ = os .path .split (dst )
721
730
722
731
# If we're uploading to S3
723
732
if s3_flag :
724
- dst = dst .replace (outdir , self .inputs .base_directory )
725
- self ._upload_to_s3 (src , dst )
726
- out_files .append (dst )
733
+ self ._upload_to_s3 (src , s3dst )
734
+ out_files .append (s3dst )
727
735
# Otherwise, copy locally src -> dst
728
- else :
736
+ if not s3_flag or isdefined ( self . inputs . local_copy ) :
729
737
# Create output directory if it doesnt exist
730
738
if not os .path .exists (path ):
731
739
try :
@@ -787,6 +795,8 @@ class S3DataSinkInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
787
795
_outputs = traits .Dict (traits .Str , value = {}, usedefault = True )
788
796
remove_dest_dir = traits .Bool (False , usedefault = True ,
789
797
desc = 'remove dest directory when copying dirs' )
798
+ # Set this if user wishes to have local copy of files as well
799
+ local_copy = traits .Str (desc = 'Copy files locally as well as to S3 bucket' )
790
800
791
801
def __setattr__ (self , key , value ):
792
802
if key not in self .copyable_trait_names ():
0 commit comments