X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/aaa964ac44f923985d6a6eb40c179f62c13ca8ce..a6be53f6913862b3884c57e9e93a891f3cfec471:/sdk/cwl/arvados_cwl/pathmapper.py diff --git a/sdk/cwl/arvados_cwl/pathmapper.py b/sdk/cwl/arvados_cwl/pathmapper.py index 74d9481ff5..a8619a8598 100644 --- a/sdk/cwl/arvados_cwl/pathmapper.py +++ b/sdk/cwl/arvados_cwl/pathmapper.py @@ -2,10 +2,13 @@ import re import logging import uuid import os +import urllib import arvados.commands.run import arvados.collection +from schema_salad.sourceline import SourceLine + from cwltool.pathmapper import PathMapper, MapperEnt, abspath, adjustFileObjs, adjustDirObjs from cwltool.workflow import WorkflowException @@ -15,7 +18,7 @@ class ArvPathMapper(PathMapper): """Convert container-local paths to and from Keep collection ids.""" pdh_path = re.compile(r'^keep:[0-9a-f]{32}\+\d+/.+$') - pdh_dirpath = re.compile(r'^keep:[0-9a-f]{32}\+\d+(/.+)?$') + pdh_dirpath = re.compile(r'^keep:[0-9a-f]{32}\+\d+(/.*)?$') def __init__(self, arvrunner, referenced_files, input_basedir, collection_pattern, file_pattern, name=None, **kwargs): @@ -32,31 +35,32 @@ class ArvPathMapper(PathMapper): if "#" in src: src = src[:src.index("#")] if isinstance(src, basestring) and ArvPathMapper.pdh_path.match(src): - self._pathmap[src] = MapperEnt(src, self.collection_pattern % src[5:], "File") + self._pathmap[src] = MapperEnt(src, self.collection_pattern % urllib.unquote(src[5:]), "File") if src not in self._pathmap: # Local FS ref, may need to be uploaded or may be on keep # mount. ab = abspath(src, self.input_basedir) st = arvados.commands.run.statfile("", ab, fnPattern="keep:%s/%s") - if isinstance(st, arvados.commands.run.UploadFile): - uploadfiles.add((src, ab, st)) - elif isinstance(st, arvados.commands.run.ArvFile): - self._pathmap[src] = MapperEnt(st.fn, self.collection_pattern % st.fn[5:], "File") - elif src.startswith("_:"): - if "contents" in srcobj: - pass + with SourceLine(srcobj, "location", WorkflowException): + if isinstance(st, arvados.commands.run.UploadFile): + uploadfiles.add((src, ab, st)) + elif isinstance(st, arvados.commands.run.ArvFile): + self._pathmap[src] = MapperEnt(st.fn, self.collection_pattern % urllib.unquote(st.fn[5:]), "File") + elif src.startswith("_:"): + if "contents" in srcobj: + pass + else: + raise WorkflowException("File literal '%s' is missing contents" % src) + elif src.startswith("arvwf:"): + self._pathmap[src] = MapperEnt(src, src, "File") else: - raise WorkflowException("File literal '%s' is missing contents" % src) - elif src.startswith("arvwf:"): - self._pathmap[src] = MapperEnt(src, src, "File") - else: - raise WorkflowException("Input file path '%s' is invalid" % st) + raise WorkflowException("Input file path '%s' is invalid" % st) if "secondaryFiles" in srcobj: for l in srcobj["secondaryFiles"]: self.visit(l, uploadfiles) elif srcobj["class"] == "Directory": if isinstance(src, basestring) and ArvPathMapper.pdh_dirpath.match(src): - self._pathmap[src] = MapperEnt(src, self.collection_pattern % src[5:], "Directory") + self._pathmap[src] = MapperEnt(src, self.collection_pattern % urllib.unquote(src[5:]), "Directory") for l in srcobj.get("listing", []): self.visit(l, uploadfiles) @@ -76,14 +80,18 @@ class ArvPathMapper(PathMapper): with c.open(path + "/" + obj["basename"], "w") as f: f.write(obj["contents"].encode("utf-8")) else: - raise WorkflowException("Don't know what to do with '%s'" % obj["location"]) + raise SourceLine(obj, "location", WorkflowException).makeError("Don't know what to do with '%s'" % obj["location"]) def setup(self, referenced_files, basedir): # type: (List[Any], unicode) -> None uploadfiles = set() - for k,v in self.arvrunner.get_uploaded().iteritems(): - self._pathmap[k] = MapperEnt(v.resolved, self.collection_pattern % v.resolved[5:], "File") + already_uploaded = self.arvrunner.get_uploaded() + for k in referenced_files: + loc = k["location"] + if loc in already_uploaded: + v = already_uploaded[loc] + self._pathmap[loc] = MapperEnt(v.resolved, self.collection_pattern % urllib.unquote(v.resolved[5:]), "File") for srcobj in referenced_files: self.visit(srcobj, uploadfiles) @@ -98,7 +106,7 @@ class ArvPathMapper(PathMapper): project=self.arvrunner.project_uuid) for src, ab, st in uploadfiles: - self._pathmap[src] = MapperEnt(st.fn, self.collection_pattern % st.fn[5:], "File") + self._pathmap[src] = MapperEnt(urllib.quote(st.fn, "/:+@"), self.collection_pattern % st.fn[5:], "File") self.arvrunner.add_uploaded(src, self._pathmap[src]) for srcobj in referenced_files: @@ -176,7 +184,7 @@ class StagingPathMapper(PathMapper): self.visitlisting(obj.get("secondaryFiles", []), stagedir, basedir) -class InitialWorkDirPathMapper(StagingPathMapper): +class VwdPathMapper(StagingPathMapper): def setup(self, referenced_files, basedir): # type: (List[Any], unicode) -> None @@ -189,7 +197,7 @@ class InitialWorkDirPathMapper(StagingPathMapper): self._pathmap[path] = MapperEnt("$(task.keep)/%s" % ab[5:], tgt, type) -class FinalOutputPathMapper(StagingPathMapper): +class NoFollowPathMapper(StagingPathMapper): _follow_dirs = False def setup(self, referenced_files, basedir): # type: (List[Any], unicode) -> None