10383: Now --update-collection is not mutually exclusive with --resume and --no-resume.
[arvados.git] / sdk / cwl / arvados_cwl / arvtool.py
1 from cwltool.draft2tool import CommandLineTool
2 from .arvjob import ArvadosJob
3 from .arvcontainer import ArvadosContainer
4 from .pathmapper import ArvPathMapper
5
6 class ArvadosCommandTool(CommandLineTool):
7     """Wrap cwltool CommandLineTool to override selected methods."""
8
9     def __init__(self, arvrunner, toolpath_object, **kwargs):
10         super(ArvadosCommandTool, self).__init__(toolpath_object, **kwargs)
11         self.arvrunner = arvrunner
12         self.work_api = kwargs["work_api"]
13
14     def makeJobRunner(self):
15         if self.work_api == "containers":
16             return ArvadosContainer(self.arvrunner)
17         elif self.work_api == "jobs":
18             return ArvadosJob(self.arvrunner)
19
20     def makePathMapper(self, reffiles, stagedir, **kwargs):
21         # type: (List[Any], unicode, **Any) -> PathMapper
22         if self.work_api == "containers":
23             return ArvPathMapper(self.arvrunner, reffiles, kwargs["basedir"],
24                                  "/keep/%s",
25                                  "/keep/%s/%s",
26                                  **kwargs)
27         elif self.work_api == "jobs":
28             return ArvPathMapper(self.arvrunner, reffiles, kwargs["basedir"],
29                                  "$(task.keep)/%s",
30                                  "$(task.keep)/%s/%s",
31                                  **kwargs)
32
33     def job(self, joborder, output_callback, **kwargs):
34         if self.work_api == "containers":
35             kwargs["outdir"] = "/var/spool/cwl"
36             kwargs["docker_outdir"] = "/var/spool/cwl"
37         elif self.work_api == "jobs":
38             kwargs["outdir"] = "$(task.outdir)"
39             kwargs["docker_outdir"] = "$(task.outdir)"
40             kwargs["tmpdir"] = "$(task.tmpdir)"
41             kwargs["docker_tmpdir"] = "$(task.tmpdir)"
42         return super(ArvadosCommandTool, self).job(joborder, output_callback, **kwargs)