move run_aws_cp command out of class to make it easier to use from other scripts
authorDiane Trout <diane@ghic.org>
Tue, 20 Oct 2015 23:17:14 +0000 (16:17 -0700)
committerDiane Trout <diane@ghic.org>
Tue, 20 Oct 2015 23:17:14 +0000 (16:17 -0700)
htsworkflow/submission/aws_submission.py

index f4cd5c0b755179f5de40443be27130aa1b137490..06dbd601b0a1b6e52c7b5cec4a5109671755fd31 100644 (file)
@@ -61,32 +61,12 @@ class AWSSubmission(Submission):
 
                     item = response['@graph'][0]
                     creds = item['upload_credentials']
-                    self.run_aws_cp(metadata['submitted_file_name'], creds)
+                    run_aws_cp(metadata['submitted_file_name'], creds)
                 else:
                     LOGGER.info('%s already uploaded',
                                 metadata['submitted_file_name'])
 
 
-    def run_aws_cp(self, pathname, creds):
-        env = os.environ.copy()
-        env.update({
-            'AWS_ACCESS_KEY_ID': creds['access_key'],
-            'AWS_SECRET_ACCESS_KEY': creds['secret_key'],
-            'AWS_SECURITY_TOKEN': creds['session_token'],
-        })
-        start = time.time()
-        try:
-            subprocess.check_call(['aws', 's3', 'cp', pathname, creds['upload_url']], env=env)
-        except subprocess.CalledProcessError as e:
-            LOGGER.error('Upload of %s failed with exit code %d', pathname, e.returncode)
-            return
-        else:
-            end = time.time()
-            LOGGER.info('Upload of %s finished in %.2f seconds',
-                        pathname,
-                        end-start)
-
-
     def get_metadata(self, analysis_node):
         # convert our model names to encode project aliases
         platform_alias = {
@@ -116,3 +96,22 @@ class AWSSubmission(Submission):
                 row['flowcell_details'] = [flowcell_details]
 
         return results
+
+def run_aws_cp(pathname, creds):
+    env = os.environ.copy()
+    env.update({
+        'AWS_ACCESS_KEY_ID': creds['access_key'],
+        'AWS_SECRET_ACCESS_KEY': creds['secret_key'],
+        'AWS_SECURITY_TOKEN': creds['session_token'],
+    })
+    start = time.time()
+    try:
+        subprocess.check_call(['aws', 's3', 'cp', pathname, creds['upload_url']], env=env)
+    except subprocess.CalledProcessError as e:
+        LOGGER.error('Upload of %s failed with exit code %d', pathname, e.returncode)
+        return
+    else:
+        end = time.time()
+        LOGGER.info('Upload of %s finished in %.2f seconds',
+                    pathname,
+                    end-start)