raise SourceLine(obj, "location", WorkflowException).makeError("Don't know what to do with '%s'" % obj["location"])
def needs_new_collection(self, srcobj, prefix=""):
+ """Check if files need to be staged into a new collection.
+
+ If all the files are in the same collection and in the same
+ paths they would be staged to, return False. Otherwise, a new
+ collection is needed with files copied/created in the
+ appropriate places.
+ """
+
loc = srcobj["location"]
if loc.startswith("_:"):
return True
prefix = loc+"/"
if srcobj["class"] == "File" and loc not in self._pathmap:
return True
- if srcobj.get("secondaryFiles"):
- for s in srcobj["secondaryFiles"]:
- if self.needs_new_collection(s, prefix):
- return True
+ for s in srcobj.get("secondaryFiles", []):
+ if self.needs_new_collection(s, prefix):
+ return True
if srcobj.get("listing"):
prefix = "%s%s/" % (prefix, srcobj["basename"])
for l in srcobj["listing"]:
elif srcobj["class"] == "File" and (srcobj.get("secondaryFiles") or
(srcobj["location"].startswith("_:") and "contents" in srcobj)):
+ # If all secondary files/directories are located in
+ # the same collection as the primary file and the
+ # paths and names that are consistent with staging,
+ # don't create a new collection.
if not self.needs_new_collection(srcobj):
continue
def test_needs_new_collection(self):
arvrunner = arvados_cwl.executor.ArvCwlExecutor(self.api)
+
+ # Plain file. Don't need a new collection.
a = {
"class": "File",
"location": "keep:99999999999999999999999999999991+99/hw.py",
p._pathmap["keep:99999999999999999999999999999991+99/hw.py"] = True
self.assertFalse(p.needs_new_collection(a))
+ # A file that isn't in the pathmap (for some reason). Need a new collection.
p = ArvPathMapper(arvrunner, [], "", "%s", "%s/%s")
self.assertTrue(p.needs_new_collection(a))
+ # A file with a secondary file in the same collection. Don't need
+ # a new collection.
a = {
"class": "File",
"location": "keep:99999999999999999999999999999991+99/hw.py",
p._pathmap["keep:99999999999999999999999999999991+99/hw.pyc"] = True
self.assertFalse(p.needs_new_collection(a))
+ # Secondary file is in a different collection from the
+ # a new collectionprimary. Need a new collection.
a = {
"class": "File",
"location": "keep:99999999999999999999999999999991+99/hw.py",
p._pathmap["keep:99999999999999999999999999999992+99/hw.pyc"] = True
self.assertTrue(p.needs_new_collection(a))
+ # Secondary file should be staged to a different name than
+ # path in location. Need a new collection.
a = {
"class": "File",
"location": "keep:99999999999999999999999999999991+99/hw.py",
p._pathmap["keep:99999999999999999999999999999991+99/hw.pyc"] = True
self.assertTrue(p.needs_new_collection(a))
+ # Secondary file is a directory. Do not need a new collection.
a = {
"class": "File",
"location": "keep:99999999999999999999999999999991+99/hw.py",
p._pathmap["keep:99999999999999999999999999999991+99/hw/h2"] = True
self.assertFalse(p.needs_new_collection(a))
+ # Secondary file is a renamed directory. Need a new collection.
a = {
"class": "File",
"location": "keep:99999999999999999999999999999991+99/hw.py",
p._pathmap["keep:99999999999999999999999999999991+99/hw/h2"] = True
self.assertTrue(p.needs_new_collection(a))
+ # Secondary file is a file literal. Need a new collection.
a = {
"class": "File",
"location": "keep:99999999999999999999999999999991+99/hw.py",