@@ -109,8 +109,9 @@ def revmap_file(builder, outdir, f):
109
109
if f ["location" ].startswith ("file://" ):
110
110
path = convert_pathsep_to_unix (uri_file_path (f ["location" ]))
111
111
revmap_f = builder .pathmapper .reversemap (path )
112
- if revmap_f :
113
- f ["location" ] = revmap_f [1 ]
112
+ if revmap_f and not builder .pathmapper .mapper (revmap_f [0 ]).type .startswith ("Writable" ):
113
+ f ["basename" ] = os .path .basename (path )
114
+ f ["location" ] = revmap_f [0 ]
114
115
elif path == builder .outdir :
115
116
f ["location" ] = outdir
116
117
elif path .startswith (builder .outdir ):
@@ -181,13 +182,14 @@ def __init__(self, toolpath_object, **kwargs):
181
182
def makeJobRunner (self , use_container = True ): # type: (Optional[bool]) -> JobBase
182
183
dockerReq , _ = self .get_requirement ("DockerRequirement" )
183
184
if not dockerReq and use_container :
184
- default_container = self .find_default_container (self )
185
- if default_container :
186
- self .requirements .insert (0 , {
187
- "class" : "DockerRequirement" ,
188
- "dockerPull" : default_container
189
- })
190
- dockerReq = self .requirements [0 ]
185
+ if self .find_default_container :
186
+ default_container = self .find_default_container (self )
187
+ if default_container :
188
+ self .requirements .insert (0 , {
189
+ "class" : "DockerRequirement" ,
190
+ "dockerPull" : default_container
191
+ })
192
+ dockerReq = self .requirements [0 ]
191
193
192
194
if dockerReq and use_container :
193
195
return DockerCommandLineJob ()
@@ -203,6 +205,17 @@ def makePathMapper(self, reffiles, stagedir, **kwargs):
203
205
# type: (List[Any], Text, **Any) -> PathMapper
204
206
return PathMapper (reffiles , kwargs ["basedir" ], stagedir )
205
207
208
+ def updatePathmap (self , outdir , pathmap , fn ):
209
+ # type: (Text, PathMapper, Dict) -> None
210
+ if "location" in fn :
211
+ pathmap .update (fn ["location" ], pathmap .mapper (fn ["location" ]).resolved ,
212
+ os .path .join (outdir , fn ["basename" ]),
213
+ ("Writable" if fn .get ("writable" ) else "" ) + fn ["class" ], False )
214
+ for sf in fn .get ("secondaryFiles" , []):
215
+ self .updatePathmap (outdir , pathmap , sf )
216
+ for ls in fn .get ("listing" , []):
217
+ self .updatePathmap (os .path .join (outdir , fn ["basename" ]), pathmap , ls )
218
+
206
219
def job (self ,
207
220
job_order , # type: Dict[Text, Text]
208
221
output_callbacks , # type: Callable[[Any, Any], Any]
@@ -228,9 +241,9 @@ def job(self,
228
241
229
242
cmdline = flatten (list (map (cachebuilder .generate_arg , cachebuilder .bindings )))
230
243
(docker_req , docker_is_req ) = self .get_requirement ("DockerRequirement" )
231
- if docker_req and kwargs .get ("use_container" ) is not False :
244
+ if docker_req and kwargs .get ("use_container" ):
232
245
dockerimg = docker_req .get ("dockerImageId" ) or docker_req .get ("dockerPull" )
233
- elif kwargs .get ("default_container" , None ) is not None and kwargs .get ("use_container" ) is not False :
246
+ elif kwargs .get ("default_container" , None ) is not None and kwargs .get ("use_container" ):
234
247
dockerimg = kwargs .get ("default_container" )
235
248
236
249
if dockerimg :
@@ -268,7 +281,7 @@ def job(self,
268
281
jobcachepending = jobcache + ".pending"
269
282
270
283
if os .path .isdir (jobcache ) and not os .path .isfile (jobcachepending ):
271
- if docker_req and kwargs .get ("use_container" ) is not False :
284
+ if docker_req and kwargs .get ("use_container" ):
272
285
cachebuilder .outdir = kwargs .get ("docker_outdir" ) or "/var/spool/cwl"
273
286
else :
274
287
cachebuilder .outdir = jobcache
@@ -327,46 +340,10 @@ def rm_pending_output_callback(output_callbacks, jobcachepending,
327
340
builder .pathmapper = self .makePathMapper (reffiles , builder .stagedir , ** make_path_mapper_kwargs )
328
341
builder .requirements = j .requirements
329
342
330
- if _logger .isEnabledFor (logging .DEBUG ):
331
- _logger .debug (u"[job %s] path mappings is %s" , j .name ,
332
- json .dumps ({p : builder .pathmapper .mapper (p ) for p in builder .pathmapper .files ()}, indent = 4 ))
333
-
334
343
_check_adjust = partial (check_adjust , builder )
335
344
336
345
visit_class ([builder .files , builder .bindings ], ("File" , "Directory" ), _check_adjust )
337
346
338
- if self .tool .get ("stdin" ):
339
- with SourceLine (self .tool , "stdin" , validate .ValidationException ):
340
- j .stdin = builder .do_eval (self .tool ["stdin" ])
341
- reffiles .append ({"class" : "File" , "path" : j .stdin })
342
-
343
- if self .tool .get ("stderr" ):
344
- with SourceLine (self .tool , "stderr" , validate .ValidationException ):
345
- j .stderr = builder .do_eval (self .tool ["stderr" ])
346
- if os .path .isabs (j .stderr ) or ".." in j .stderr :
347
- raise validate .ValidationException ("stderr must be a relative path, got '%s'" % j .stderr )
348
-
349
- if self .tool .get ("stdout" ):
350
- with SourceLine (self .tool , "stdout" , validate .ValidationException ):
351
- j .stdout = builder .do_eval (self .tool ["stdout" ])
352
- if os .path .isabs (j .stdout ) or ".." in j .stdout or not j .stdout :
353
- raise validate .ValidationException ("stdout must be a relative path, got '%s'" % j .stdout )
354
-
355
- if _logger .isEnabledFor (logging .DEBUG ):
356
- _logger .debug (u"[job %s] command line bindings is %s" , j .name , json .dumps (builder .bindings , indent = 4 ))
357
-
358
- dockerReq = self .get_requirement ("DockerRequirement" )[0 ]
359
- if dockerReq and kwargs .get ("use_container" ):
360
- out_prefix = kwargs .get ("tmp_outdir_prefix" )
361
- j .outdir = kwargs .get ("outdir" ) or tempfile .mkdtemp (prefix = out_prefix )
362
- tmpdir_prefix = kwargs .get ('tmpdir_prefix' )
363
- j .tmpdir = kwargs .get ("tmpdir" ) or tempfile .mkdtemp (prefix = tmpdir_prefix )
364
- j .stagedir = tempfile .mkdtemp (prefix = tmpdir_prefix )
365
- else :
366
- j .outdir = builder .outdir
367
- j .tmpdir = builder .tmpdir
368
- j .stagedir = builder .stagedir
369
-
370
347
initialWorkdir = self .get_requirement ("InitialWorkDirRequirement" )[0 ]
371
348
j .generatefiles = {"class" : "Directory" , "listing" : [], "basename" : "" }
372
349
if initialWorkdir :
@@ -402,6 +379,45 @@ def rm_pending_output_callback(output_callbacks, jobcachepending,
402
379
t ["entry" ]["writable" ] = t .get ("writable" )
403
380
ls [i ] = t ["entry" ]
404
381
j .generatefiles [u"listing" ] = ls
382
+ for l in ls :
383
+ self .updatePathmap (builder .outdir , builder .pathmapper , l )
384
+ visit_class ([builder .files , builder .bindings ], ("File" , "Directory" ), _check_adjust )
385
+
386
+ if _logger .isEnabledFor (logging .DEBUG ):
387
+ _logger .debug (u"[job %s] path mappings is %s" , j .name ,
388
+ json .dumps ({p : builder .pathmapper .mapper (p ) for p in builder .pathmapper .files ()}, indent = 4 ))
389
+
390
+ if self .tool .get ("stdin" ):
391
+ with SourceLine (self .tool , "stdin" , validate .ValidationException ):
392
+ j .stdin = builder .do_eval (self .tool ["stdin" ])
393
+ reffiles .append ({"class" : "File" , "path" : j .stdin })
394
+
395
+ if self .tool .get ("stderr" ):
396
+ with SourceLine (self .tool , "stderr" , validate .ValidationException ):
397
+ j .stderr = builder .do_eval (self .tool ["stderr" ])
398
+ if os .path .isabs (j .stderr ) or ".." in j .stderr :
399
+ raise validate .ValidationException ("stderr must be a relative path, got '%s'" % j .stderr )
400
+
401
+ if self .tool .get ("stdout" ):
402
+ with SourceLine (self .tool , "stdout" , validate .ValidationException ):
403
+ j .stdout = builder .do_eval (self .tool ["stdout" ])
404
+ if os .path .isabs (j .stdout ) or ".." in j .stdout or not j .stdout :
405
+ raise validate .ValidationException ("stdout must be a relative path, got '%s'" % j .stdout )
406
+
407
+ if _logger .isEnabledFor (logging .DEBUG ):
408
+ _logger .debug (u"[job %s] command line bindings is %s" , j .name , json .dumps (builder .bindings , indent = 4 ))
409
+
410
+ dockerReq = self .get_requirement ("DockerRequirement" )[0 ]
411
+ if dockerReq and kwargs .get ("use_container" ):
412
+ out_prefix = kwargs .get ("tmp_outdir_prefix" )
413
+ j .outdir = kwargs .get ("outdir" ) or tempfile .mkdtemp (prefix = out_prefix )
414
+ tmpdir_prefix = kwargs .get ('tmpdir_prefix' )
415
+ j .tmpdir = kwargs .get ("tmpdir" ) or tempfile .mkdtemp (prefix = tmpdir_prefix )
416
+ j .stagedir = tempfile .mkdtemp (prefix = tmpdir_prefix )
417
+ else :
418
+ j .outdir = builder .outdir
419
+ j .tmpdir = builder .tmpdir
420
+ j .stagedir = builder .stagedir
405
421
406
422
inplaceUpdateReq = self .get_requirement ("http://commonwl.org/cwltool#InplaceUpdateRequirement" )[0 ]
407
423
0 commit comments