Merge branch '20933-arv-copy-cwl' refs #20933
[arvados.git] / sdk / python / arvados / commands / arv_copy.py
index d6af681ffb7a0c1b830b8345bfe34eb91d061ddc..7f5245db863acd0c9c446ce6328b58f237125a3c 100755 (executable)
@@ -171,6 +171,9 @@ def main():
     for d in listvalues(local_repo_dir):
         shutil.rmtree(d, ignore_errors=True)
 
+    if not result:
+        exit(1)
+
     # If no exception was thrown and the response does not have an
     # error_token field, presume success
     if result is None or 'error_token' in result or 'uuid' not in result:
@@ -327,13 +330,23 @@ def copy_workflow(wf_uuid, src, dst, args):
         env = {"ARVADOS_API_HOST": urllib.parse.urlparse(src._rootDesc["rootUrl"]).netloc,
                "ARVADOS_API_TOKEN": src.api_token,
                "PATH": os.environ["PATH"]}
-        result = subprocess.run(["arvados-cwl-runner", "--quiet", "--print-keep-deps", "arvwf:"+wf_uuid],
-                                env=env)
-        print(result)
-        exit()
+        try:
+            result = subprocess.run(["arvados-cwl-runner", "--quiet", "--print-keep-deps", "arvwf:"+wf_uuid],
+                                    capture_output=True, env=env)
+        except FileNotFoundError:
+            no_arv_copy = True
+        else:
+            no_arv_copy = result.returncode == 2
+
+        if no_arv_copy:
+            raise Exception('Copying workflows requires arvados-cwl-runner 2.7.1 or later to be installed in PATH.')
+        elif result.returncode != 0:
+            raise Exception('There was an error getting Keep dependencies from workflow using arvados-cwl-runner --print-keep-deps')
+
+        locations = json.loads(result.stdout)
 
-        #if locations:
-        #        copy_collections(locations, src, dst, args)
+        if locations:
+            copy_collections(locations, src, dst, args)
 
     # copy the workflow itself
     del wf['uuid']