Skip to content

Commit 2fda58a

Browse files
committed
More generic open_log_file_for_activity
1 parent 66d8c23 commit 2fda58a

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

cwltool/provenance.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class PermissionError(OSError): # pylint: disable=redefined-builtin
8282
# sub-folders
8383
MAIN = os.path.join(WORKFLOW, "main")
8484
PROVENANCE = os.path.join(METADATA, "provenance")
85+
LOGS = os.path.join(METADATA, "logs")
8586
WFDESC = Namespace("wfdesc", 'http://purl.org/wf4ever/wfdesc#')
8687
WFPROV = Namespace("wfprov", 'http://purl.org/wf4ever/wfprov#')
8788
WF4EVER = Namespace("wf4ever", 'http://purl.org/wf4ever/wf4ever#')
@@ -999,7 +1000,7 @@ def __str__(self):
9991000

10001001
def _initialize(self): # type: () -> None
10011002
for research_obj_folder in (METADATA, DATA, WORKFLOW, SNAPSHOT,
1002-
PROVENANCE):
1003+
PROVENANCE, LOGS):
10031004
os.makedirs(os.path.join(self.folder, research_obj_folder))
10041005
self._initialize_bagit()
10051006

@@ -1013,17 +1014,19 @@ def _initialize_bagit(self): # type: () -> None
10131014
# TODO: \n or \r\n ?
10141015
bag_it_file.write(u"BagIt-Version: 0.97\n")
10151016
bag_it_file.write(u"Tag-File-Character-Encoding: %s\n" % ENCODING)
1016-
1017-
def write_log(self, log_path): # type: (Text) -> None
1018-
"""Copies log files to the snapshot/ directory."""
1017+
1018+
def open_log_file_for_activity(self, uuid_uri): # type: (Text) -> IO
10191019
self.self_check()
1020-
dst_path = os.path.join(
1021-
self.folder, SNAPSHOT, os.path.basename(log_path))
1022-
while os.path.exists(dst_path):
1023-
dst_path = dst_path + "_{}".format(uuid.uuid4())
1024-
shutil.move(log_path, dst_path)
1025-
when = datetime.datetime.fromtimestamp(os.path.getmtime(dst_path))
1026-
self.add_tagfile(dst_path, when)
1020+
# Ensure valid UUID for safe filenames
1021+
activity_uuid = uuid.UUID(uuid_uri.replace("urn:uuid:", ""))
1022+
if activity_uuid.urn == self.engine_uuid:
1023+
# It's the engine aka cwltool!
1024+
name = "engine"
1025+
else:
1026+
name = "activity"
1027+
p = os.path.join(LOGS, "%s.%s.txt" % (name, activity_uuid))
1028+
_logger.debug("[provenance] Opening log file for %s: %s" % (name, p))
1029+
return self.write_bag_file(p)
10271030

10281031
def _finalize(self): # type: () -> None
10291032
self._write_ro_manifest()

0 commit comments

Comments
 (0)