+ if "task.foreach" in jobp:
+ if arvados.current_task()['sequence'] == 0:
+ # This is the first task to start the other tasks and exit
+ fvars = jobp["task.foreach"]
+ if isinstance(fvars, basestring):
+ fvars = [fvars]
+ if not isinstance(fvars, list) or len(fvars) == 0:
+ logger.error("value of task.foreach must be a string or non-empty list")
+ sys.exit(1)
+ recursive_foreach(jobp, jobp["task.foreach"])
+ if "task.vwd" in jobp:
+ # Set output of the first task to the base vwd collection so it
+ # will be merged with output fragments from the other tasks by
+ # crunch.
+ arvados.current_task().set_output(subst.do_substitution(jobp, jobp["task.vwd"]))
+ else:
+ arvados.current_task().set_output(None)
+ sys.exit(0)
+ else:
+ # This is the only task so taskp/jobp are the same
+ taskp = jobp
+
+ if "task.vwd" in taskp:
+ # Populate output directory with symlinks to files in collection
+ vwd.checkout(subst.do_substitution(taskp, taskp["task.vwd"]), outdir)
+
+ if "task.cwd" in taskp:
+ os.chdir(subst.do_substitution(taskp, taskp["task.cwd"]))
+
+ cmd = expand_list(taskp, taskp["command"])
+
+ if "task.stdin" in taskp:
+ stdinname = subst.do_substitution(taskp, taskp["task.stdin"])
+ stdinfile = open(stdinname, "rb")