@@ -59,5 +59,50 @@ def data(output_dir):
59
59
print ('done' )
60
60
61
61
62
+ @click .command ()
63
+ @click .argument ('output_dir' )
64
+ @click .argument ('bucket' )
65
+ @click .option ('--access_key' , help = "your AWS access key" )
66
+ @click .option ('--secret_key' , help = "your AWS access secret" )
67
+ @click .option ('--provider' , default = 's3' , help = "Cloud storage provider. Only S3 is supported right now." )
68
+ @click .option ('--subject' , default = None , help = "Subject id to upload (optional)" )
69
+ def upload (output_dir , bucket , access_key , secret_key , provider = 's3' , subject = None ):
70
+ """
71
+ OUTPUT_DIR: The directory where the output files were stored.
72
+
73
+ BUCKET: The cloud bucket name to upload data to.
74
+ """
75
+
76
+ import boto3
77
+ from glob import glob
78
+
79
+ output_dir = os .path .abspath (output_dir )
80
+ if not output_dir .endswith ('/' ):
81
+ output_dir += '/'
82
+
83
+ if provider == 's3' or provider == 'S3' :
84
+ client = boto3 .client ('s3' , aws_access_key_id = access_key , aws_secret_access_key = secret_key )
85
+
86
+ if subject is not None :
87
+ assert os .path .exists (os .path .join (output_dir , subject )), 'this subject id does not exist!'
88
+ subjects = [subject ]
89
+ else :
90
+ subjects = [os .path .split (s )[1 ] for s in glob (os .path .join (output_dir , 'sub-*' ))]
91
+
92
+ for s in subjects :
93
+ base_dir = os .path .join (output_dir , s , 'dmriprep' )
94
+ for root , dirs , files in os .walk (base_dir ):
95
+ for f in files :
96
+ filepath = os .path .join (root , f )
97
+ key = root .replace (output_dir , '' )
98
+ # TODO: progress bar on this!!
99
+ client .upload_file (filepath , bucket , os .path .join (key , f ))
100
+
101
+
102
+
103
+ else :
104
+ raise NotImplementedError ('Only S3 is the only supported provider for data uploads at the moment' )
105
+
106
+
62
107
if __name__ == "__main__" :
63
108
sys .exit (main ()) # pragma: no cover
0 commit comments