1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 from cwltool.draft2tool import CommandLineTool
6 from .arvjob import ArvadosJob
7 from .arvcontainer import ArvadosContainer
8 from .pathmapper import ArvPathMapper
10 class ArvadosCommandTool(CommandLineTool):
11 """Wrap cwltool CommandLineTool to override selected methods."""
13 def __init__(self, arvrunner, toolpath_object, **kwargs):
14 super(ArvadosCommandTool, self).__init__(toolpath_object, **kwargs)
15 self.arvrunner = arvrunner
16 self.work_api = kwargs["work_api"]
18 def makeJobRunner(self, **kwargs):
19 if self.work_api == "containers":
20 return ArvadosContainer(self.arvrunner)
21 elif self.work_api == "jobs":
22 return ArvadosJob(self.arvrunner)
24 def makePathMapper(self, reffiles, stagedir, **kwargs):
25 # type: (List[Any], unicode, **Any) -> PathMapper
26 if self.work_api == "containers":
27 return ArvPathMapper(self.arvrunner, reffiles, kwargs["basedir"],
31 elif self.work_api == "jobs":
32 return ArvPathMapper(self.arvrunner, reffiles, kwargs["basedir"],
37 def job(self, joborder, output_callback, **kwargs):
38 if self.work_api == "containers":
39 kwargs["outdir"] = "/var/spool/cwl"
40 kwargs["docker_outdir"] = "/var/spool/cwl"
41 elif self.work_api == "jobs":
42 kwargs["outdir"] = "$(task.outdir)"
43 kwargs["docker_outdir"] = "$(task.outdir)"
44 kwargs["tmpdir"] = "$(task.tmpdir)"
45 kwargs["docker_tmpdir"] = "$(task.tmpdir)"
46 return super(ArvadosCommandTool, self).job(joborder, output_callback, **kwargs)