11 import arvados.commands.put as put
15 t = arvados.current_task().tmpdir
17 api = arvados.api('v1')
19 os.chdir(arvados.current_task().tmpdir)
25 if len(arvados.current_task()['parameters']) > 0:
26 p = arvados.current_task()['parameters']
28 p = arvados.current_job()['script_parameters']
33 r = os.path.basename(v)
34 os.symlink(os.path.join(os.environ['TASK_KEEPMOUNT'], v) , r)
39 return os.path.join(arvados.current_task().tmpdir, 'tmpdir')
42 return os.environ['CRUNCH_NODE_SLOTS']
44 subst.default_subs["link "] = sub_link
45 subst.default_subs["tmpdir"] = sub_tmpdir
46 subst.default_subs["node.cores"] = sub_cores
50 def machine_progress(bytes_written, bytes_expected):
51 return "run-command: {} written {} total\n".format(
52 bytes_written, -1 if (bytes_expected is None) else bytes_expected)
56 for c in p["command"]:
57 cmd.append(subst.do_substitution(p, c))
62 stdoutname = subst.do_substitution(p, p["stdout"])
63 stdoutfile = open(stdoutname, "wb")
65 print("run-command: {}{}".format(' '.join(cmd), (" > " + stdoutname) if stdoutname != None else ""))
67 rcode = subprocess.call(cmd, stdout=stdoutfile)
69 print("run-command: completed with exit code %i (%s)" % (rcode, "success" if rcode == 0 else "failed"))
71 except Exception as e:
72 print("run-command: caught exception: {}".format(e))
78 print("run-command: the follow output files will be saved to keep:")
80 subprocess.call(["find", ".", "-type", "f", "-printf", "run-command: %12.12s %h/%f\\n"])
82 print("run-command: start writing output to keep")
85 resume_cache = put.ResumeCache(os.path.join(arvados.current_task().tmpdir, "upload-output-checkpoint"))
86 reporter = put.progress_writer(machine_progress)
87 bytes_expected = put.expected_bytes_for(".")
90 out = put.ArvPutCollectionWriter(resume_cache, reporter, bytes_expected)
92 out.write_directory_tree(".", max_manifest_depth=0)
93 outuuid = out.finish()
94 api.job_tasks().update(uuid=arvados.current_task()['uuid'],
97 'success': (rcode == 0),
101 except Exception as e:
102 print("run-command: caught exception: {}".format(e))