Merge branch 'master' into 9369-arv-cwl-docs
[arvados.git] / sdk / cwl / arvados_cwl / pathmapper.py
index 12f7cd7021dc012e5a8945504552d404fd1e4a6b..fb4ae5ad45ffdb3331dc5151915cb71987d241b5 100644 (file)
@@ -1,5 +1,6 @@
 import re
 import logging
+import uuid
 
 import arvados.commands.run
 import arvados.collection
@@ -123,6 +124,9 @@ class ArvPathMapper(PathMapper):
 
                 ab = self.file_pattern % (c.portable_data_hash(), srcobj["basename"])
                 self._pathmap[srcobj["location"]] = MapperEnt(ab, ab, "File")
+                if srcobj.get("secondaryFiles"):
+                    ab = self.collection_pattern % c.portable_data_hash()
+                    self._pathmap["_:" + unicode(uuid.uuid4())] = MapperEnt(ab, ab, "Directory")
                 for loc, sub in subdirs:
                     ab = self.file_pattern % (c.portable_data_hash(), sub[2:])
                     self._pathmap[loc] = MapperEnt(ab, ab, "Directory")
@@ -136,3 +140,17 @@ class ArvPathMapper(PathMapper):
             return (target, "keep:" + target[len(self.keepdir)+1:])
         else:
             return super(ArvPathMapper, self).reversemap(target)
+
+class InitialWorkDirPathMapper(PathMapper):
+    def setup(self, referenced_files, basedir):
+        # type: (List[Any], unicode) -> None
+
+        # Go through each file and set the target to its own directory along
+        # with any secondary files.
+        stagedir = self.stagedir
+        for fob in referenced_files:
+            self.visit(fob, stagedir, basedir)
+
+        for path, (ab, tgt, type) in self._pathmap.items():
+            if type in ("File", "Directory") and ab.startswith("keep:"):
+                self._pathmap[path] = MapperEnt("$(task.keep)/%s" % ab[5:], tgt, type)