Skip to content

Commit 54e3502

Browse files
kannon92mr-c
authored andcommitted
feat: add callback for log copying
1 parent 51d7a97 commit 54e3502

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

cwltool/context.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Shared context objects that replace use of kwargs."""
22
import copy
33
import os
4+
import shutil
45
import tempfile
56
import threading
67
from typing import (
@@ -55,6 +56,21 @@ def make_tool_notimpl(
5556

5657
default_make_tool = make_tool_notimpl
5758

59+
# Move logs from log location to final output
60+
def log_handler(
61+
outdir: str,
62+
base_path_logs: str,
63+
stdout_path: Optional[str],
64+
stderr_path: Optional[str],
65+
) -> None:
66+
if outdir != base_path_logs:
67+
if stdout_path:
68+
new_stdout_path = stdout_path.replace(base_path_logs, outdir)
69+
shutil.copy2(stdout_path, new_stdout_path)
70+
if stderr_path:
71+
new_stderr_path = stderr_path.replace(base_path_logs, outdir)
72+
shutil.copy2(stderr_path, new_stderr_path)
73+
5874

5975
class LoadingContext(ContextBase):
6076
def __init__(self, kwargs: Optional[Dict[str, Any]] = None) -> None:
@@ -119,6 +135,7 @@ def __init__(self, kwargs: Optional[Dict[str, Any]] = None) -> None:
119135
self.rm_container = True # type: bool
120136
self.move_outputs = "move" # type: str
121137
self.log_dir = "" # type: str
138+
self.log_dir_handler = log_handler
122139
self.streaming_allowed: bool = False
123140

124141
self.singularity = False # type: bool

cwltool/job.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
Union,
3232
cast,
3333
)
34-
3534
import psutil
3635
import shellescape
3736
from prov.model import PROV
@@ -393,19 +392,9 @@ def stderr_stdout_log_path(
393392
"'listing' in self.generatefiles but no "
394393
"generatemapper was setup."
395394
)
396-
# Move logs from log location to final output
397-
if self.outdir != self.base_path_logs:
398-
if stdout_path:
399-
new_stdout_path = stdout_path.replace(
400-
self.base_path_logs, self.outdir
401-
)
402-
shutil.copy2(stdout_path, new_stdout_path)
403-
if stderr_path:
404-
new_stderr_path = stderr_path.replace(
405-
self.base_path_logs, self.outdir
406-
)
407-
shutil.copy2(stderr_path, new_stderr_path)
408-
395+
runtimeContext.log_dir_handler(
396+
self.outdir, self.base_path_logs, stdout_path, stderr_path
397+
)
409398
outputs = self.collect_outputs(self.outdir, rcode)
410399
outputs = bytes2str_in_dicts(outputs) # type: ignore
411400
except OSError as e:

0 commit comments

Comments
 (0)