@@ -436,151 +436,155 @@ def main(argsl=None,
436
436
# type: (List[str],Callable[...,Union[str,Dict[str,str]]],Callable[...,Process],Callable[[Dict[str,int]],Dict[str,int]],argparse.ArgumentParser,IO[Any],IO[Any],IO[Any],Callable[[],unicode]) -> int
437
437
438
438
_logger .removeHandler (defaultStreamHandler )
439
- _logger .addHandler (logging .StreamHandler (stderr ))
440
-
441
- if argsl is None :
442
- argsl = sys .argv [1 :]
439
+ stderr_handler = logging .StreamHandler (stderr )
440
+ _logger .addHandler (stderr_handler )
441
+ try :
442
+ if argsl is None :
443
+ argsl = sys .argv [1 :]
443
444
444
- if parser is None :
445
- parser = arg_parser ()
445
+ if parser is None :
446
+ parser = arg_parser ()
446
447
447
- args = parser .parse_args (argsl )
448
+ args = parser .parse_args (argsl )
448
449
449
- if args .quiet :
450
- _logger .setLevel (logging .WARN )
451
- if args .debug :
452
- _logger .setLevel (logging .DEBUG )
450
+ if args .quiet :
451
+ _logger .setLevel (logging .WARN )
452
+ if args .debug :
453
+ _logger .setLevel (logging .DEBUG )
453
454
454
- if args .version :
455
- print versionfunc ()
456
- return 0
457
- else :
458
- _logger .info (versionfunc ())
455
+ if args .version :
456
+ print versionfunc ()
457
+ return 0
458
+ else :
459
+ _logger .info (versionfunc ())
459
460
460
- if not args .workflow :
461
- parser .print_help ()
462
- _logger .error ("" )
463
- _logger .error ("CWL document required" )
464
- return 1
461
+ if not args .workflow :
462
+ parser .print_help ()
463
+ _logger .error ("" )
464
+ _logger .error ("CWL document required" )
465
+ return 1
465
466
466
- try :
467
- document_loader , workflowobj , uri = fetch_document (args .workflow )
467
+ try :
468
+ document_loader , workflowobj , uri = fetch_document (args .workflow )
468
469
469
- if args .print_deps :
470
- printdeps (workflowobj , document_loader , stdout , args .relative_deps )
471
- return 0
470
+ if args .print_deps :
471
+ printdeps (workflowobj , document_loader , stdout , args .relative_deps )
472
+ return 0
472
473
473
- document_loader , avsc_names , processobj , metadata , uri \
474
- = validate_document (document_loader , workflowobj , uri ,
475
- enable_dev = args .enable_dev , strict = args .strict ,
476
- preprocess_only = args .print_pre )
474
+ document_loader , avsc_names , processobj , metadata , uri \
475
+ = validate_document (document_loader , workflowobj , uri ,
476
+ enable_dev = args .enable_dev , strict = args .strict ,
477
+ preprocess_only = args .print_pre )
477
478
478
- if args .print_pre :
479
- stdout .write (json .dumps (processobj , indent = 4 ))
480
- return 0
479
+ if args .print_pre :
480
+ stdout .write (json .dumps (processobj , indent = 4 ))
481
+ return 0
481
482
482
- if args .print_rdf :
483
- printrdf (uri , processobj , document_loader .ctx , args .rdf_serializer , stdout )
484
- return 0
483
+ if args .print_rdf :
484
+ printrdf (uri , processobj , document_loader .ctx , args .rdf_serializer , stdout )
485
+ return 0
485
486
486
- if args .print_dot :
487
- printdot (uri , processobj , document_loader .ctx , stdout )
488
- return 0
487
+ if args .print_dot :
488
+ printdot (uri , processobj , document_loader .ctx , stdout )
489
+ return 0
489
490
490
- tool = make_tool (document_loader , avsc_names , processobj , metadata ,
491
- uri , makeTool , {})
492
- except (validate .ValidationException ) as exc :
493
- _logger .error (u"Tool definition failed validation:\n %s" , exc ,
494
- exc_info = (exc if args .debug else False ))
495
- return 1
496
- except (RuntimeError , WorkflowException ) as exc :
497
- _logger .error (u"Tool definition failed initialization:\n %s" , exc ,
498
- exc_info = (exc if args .debug else False ))
499
- return 1
500
- except Exception as exc :
501
- _logger .error (
502
- u"I'm sorry, I couldn't load this CWL file%s" ,
503
- ", try again with --debug for more information.\n The error was: "
504
- "%s" % exc if not args .debug else ". The error was:" ,
505
- exc_info = (exc if args .debug else False ))
506
- return 1
491
+ tool = make_tool (document_loader , avsc_names , processobj , metadata ,
492
+ uri , makeTool , {})
493
+ except (validate .ValidationException ) as exc :
494
+ _logger .error (u"Tool definition failed validation:\n %s" , exc ,
495
+ exc_info = (exc if args .debug else False ))
496
+ return 1
497
+ except (RuntimeError , WorkflowException ) as exc :
498
+ _logger .error (u"Tool definition failed initialization:\n %s" , exc ,
499
+ exc_info = (exc if args .debug else False ))
500
+ return 1
501
+ except Exception as exc :
502
+ _logger .error (
503
+ u"I'm sorry, I couldn't load this CWL file%s" ,
504
+ ", try again with --debug for more information.\n The error was: "
505
+ "%s" % exc if not args .debug else ". The error was:" ,
506
+ exc_info = (exc if args .debug else False ))
507
+ return 1
507
508
508
- if isinstance (tool , int ):
509
- return tool
509
+ if isinstance (tool , int ):
510
+ return tool
510
511
511
- if args .tmp_outdir_prefix != 'tmp' :
512
- # Use user defined temp directory (if it exists)
513
- args .tmp_outdir_prefix = os .path .abspath (args .tmp_outdir_prefix )
514
- if not os .path .exists (args .tmp_outdir_prefix ):
515
- _logger .error ("Intermediate output directory prefix doesn't exist, reverting to default" )
516
- return 1
512
+ if args .tmp_outdir_prefix != 'tmp' :
513
+ # Use user defined temp directory (if it exists)
514
+ args .tmp_outdir_prefix = os .path .abspath (args .tmp_outdir_prefix )
515
+ if not os .path .exists (args .tmp_outdir_prefix ):
516
+ _logger .error ("Intermediate output directory prefix doesn't exist, reverting to default" )
517
+ return 1
517
518
518
- if args .tmpdir_prefix != 'tmp' :
519
- # Use user defined prefix (if the folder exists)
520
- args .tmpdir_prefix = os .path .abspath (args .tmpdir_prefix )
521
- if not os .path .exists (args .tmpdir_prefix ):
522
- _logger .error ("Temporary directory prefix doesn't exist." )
523
- return 1
519
+ if args .tmpdir_prefix != 'tmp' :
520
+ # Use user defined prefix (if the folder exists)
521
+ args .tmpdir_prefix = os .path .abspath (args .tmpdir_prefix )
522
+ if not os .path .exists (args .tmpdir_prefix ):
523
+ _logger .error ("Temporary directory prefix doesn't exist." )
524
+ return 1
524
525
525
- job_order_object = load_job_order (args , tool , parser , stdin ,
526
- print_input_deps = args .print_input_deps ,
527
- relative_deps = args .relative_deps ,
528
- stdout = stdout )
526
+ job_order_object = load_job_order (args , tool , parser , stdin ,
527
+ print_input_deps = args .print_input_deps ,
528
+ relative_deps = args .relative_deps ,
529
+ stdout = stdout )
529
530
530
- if isinstance (job_order_object , int ):
531
- return job_order_object
531
+ if isinstance (job_order_object , int ):
532
+ return job_order_object
532
533
533
- if args .cachedir :
534
- args .cachedir = os .path .abspath (args .cachedir )
535
- args .move_outputs = False
534
+ if args .cachedir :
535
+ args .cachedir = os .path .abspath (args .cachedir )
536
+ args .move_outputs = False
536
537
537
- try :
538
- out = executor (tool , job_order_object [0 ],
539
- job_order_object [1 ], args ,
540
- conformance_test = args .conformance_test ,
541
- dry_run = args .dry_run ,
542
- outdir = args .outdir ,
543
- tmp_outdir_prefix = args .cachedir if args .cachedir else args .tmp_outdir_prefix ,
544
- use_container = args .use_container ,
545
- preserve_environment = args .preserve_environment ,
546
- pull_image = args .enable_pull ,
547
- rm_container = args .rm_container ,
548
- tmpdir_prefix = args .tmpdir_prefix ,
549
- enable_net = args .enable_net ,
550
- rm_tmpdir = args .rm_tmpdir ,
551
- makeTool = makeTool ,
552
- move_outputs = args .move_outputs ,
553
- select_resources = selectResources ,
554
- eval_timeout = args .eval_timeout ,
555
- cachedir = args .cachedir
556
- )
557
- # This is the workflow output, it needs to be written
558
- if out is not None :
559
- if isinstance (out , basestring ):
560
- stdout .write (out )
538
+ try :
539
+ out = executor (tool , job_order_object [0 ],
540
+ job_order_object [1 ], args ,
541
+ conformance_test = args .conformance_test ,
542
+ dry_run = args .dry_run ,
543
+ outdir = args .outdir ,
544
+ tmp_outdir_prefix = args .cachedir if args .cachedir else args .tmp_outdir_prefix ,
545
+ use_container = args .use_container ,
546
+ preserve_environment = args .preserve_environment ,
547
+ pull_image = args .enable_pull ,
548
+ rm_container = args .rm_container ,
549
+ tmpdir_prefix = args .tmpdir_prefix ,
550
+ enable_net = args .enable_net ,
551
+ rm_tmpdir = args .rm_tmpdir ,
552
+ makeTool = makeTool ,
553
+ move_outputs = args .move_outputs ,
554
+ select_resources = selectResources ,
555
+ eval_timeout = args .eval_timeout ,
556
+ cachedir = args .cachedir
557
+ )
558
+ # This is the workflow output, it needs to be written
559
+ if out is not None :
560
+ if isinstance (out , basestring ):
561
+ stdout .write (out )
562
+ else :
563
+ stdout .write (json .dumps (out , indent = 4 ))
564
+ stdout .write ("\n " )
565
+ stdout .flush ()
561
566
else :
562
- stdout .write (json .dumps (out , indent = 4 ))
563
- stdout .write ("\n " )
564
- stdout .flush ()
565
- else :
567
+ return 1
568
+ except (validate .ValidationException ) as exc :
569
+ _logger .error (
570
+ u"Input object failed validation:\n %s" , exc ,
571
+ exc_info = (exc if args .debug else False ))
572
+ return 1
573
+ except WorkflowException as exc :
574
+ _logger .error (
575
+ u"Workflow error, try again with --debug for more "
576
+ "information:\n %s" , exc , exc_info = (exc if args .debug else False ))
577
+ return 1
578
+ except Exception as exc :
579
+ _logger .error (
580
+ u"Unhandled error, try again with --debug for more information:\n "
581
+ " %s" , exc , exc_info = (exc if args .debug else False ))
566
582
return 1
567
- except (validate .ValidationException ) as exc :
568
- _logger .error (
569
- u"Input object failed validation:\n %s" , exc ,
570
- exc_info = (exc if args .debug else False ))
571
- return 1
572
- except WorkflowException as exc :
573
- _logger .error (
574
- u"Workflow error, try again with --debug for more "
575
- "information:\n %s" , exc , exc_info = (exc if args .debug else False ))
576
- return 1
577
- except Exception as exc :
578
- _logger .error (
579
- u"Unhandled error, try again with --debug for more information:\n "
580
- " %s" , exc , exc_info = (exc if args .debug else False ))
581
- return 1
582
583
583
- return 0
584
+ return 0
585
+ finally :
586
+ _logger .removeHandler (stderr_handler )
587
+ _logger .addHandler (defaultStreamHandler )
584
588
585
589
if __name__ == "__main__" :
586
590
sys .exit (main (sys .argv [1 :]))
0 commit comments