@@ -82,6 +82,7 @@ class PermissionError(OSError): # pylint: disable=redefined-builtin
82
82
# sub-folders
83
83
MAIN = os .path .join (WORKFLOW , "main" )
84
84
PROVENANCE = os .path .join (METADATA , "provenance" )
85
+ LOGS = os .path .join (METADATA , "logs" )
85
86
WFDESC = Namespace ("wfdesc" , 'http://purl.org/wf4ever/wfdesc#' )
86
87
WFPROV = Namespace ("wfprov" , 'http://purl.org/wf4ever/wfprov#' )
87
88
WF4EVER = Namespace ("wf4ever" , 'http://purl.org/wf4ever/wf4ever#' )
@@ -999,7 +1000,7 @@ def __str__(self):
999
1000
1000
1001
def _initialize (self ): # type: () -> None
1001
1002
for research_obj_folder in (METADATA , DATA , WORKFLOW , SNAPSHOT ,
1002
- PROVENANCE ):
1003
+ PROVENANCE , LOGS ):
1003
1004
os .makedirs (os .path .join (self .folder , research_obj_folder ))
1004
1005
self ._initialize_bagit ()
1005
1006
@@ -1013,17 +1014,19 @@ def _initialize_bagit(self): # type: () -> None
1013
1014
# TODO: \n or \r\n ?
1014
1015
bag_it_file .write (u"BagIt-Version: 0.97\n " )
1015
1016
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
1019
1019
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 )
1027
1030
1028
1031
def _finalize (self ): # type: () -> None
1029
1032
self ._write_ro_manifest ()
0 commit comments