@@ -305,9 +305,14 @@ def __init__(self,
305
305
host_provenance , # type: bool
306
306
user_provenance , # type: bool
307
307
orcid , # type: str
308
- run_uuid = None # type: Optional[uuid.UUID]
308
+ run_uuid = None , # type: Optional[uuid.UUID],
309
+ fsaccess = None # type: Optional[StdFsAccess]
309
310
): # type: (...) -> None
310
311
"""Initialize the provenance profile."""
312
+ if not fsaccess :
313
+ fsaccess = StdFsAccess ('' )
314
+ self .fsaccess = fsaccess
315
+
311
316
self .orcid = orcid
312
317
self .research_object = research_object
313
318
self .folder = self .research_object .folder
@@ -504,8 +509,7 @@ def declare_file(self, value):
504
509
if not entity and 'location' in value :
505
510
location = str (value ['location' ])
506
511
# If we made it here, we'll have to add it to the RO
507
- fsaccess = StdFsAccess ("" )
508
- with fsaccess .open (location , "rb" ) as fhandle :
512
+ with self .fsaccess .open (location , "rb" ) as fhandle :
509
513
relative_path = self .research_object .add_data_file (fhandle )
510
514
# FIXME: This naively relies on add_data_file setting hash as filename
511
515
checksum = PurePath (relative_path ).name
@@ -592,8 +596,7 @@ def declare_directory(self, value): # type: (MutableMapping[Text, Any]) -> Prov
592
596
is_empty = True
593
597
594
598
if "listing" not in value :
595
- fsaccess = StdFsAccess ("" )
596
- get_listing (fsaccess , value )
599
+ get_listing (self .fsaccess , value )
597
600
for entry in value .get ("listing" , []):
598
601
is_empty = False
599
602
# Declare child-artifacts
@@ -937,8 +940,9 @@ def finalize_prov_profile(self, name):
937
940
class ResearchObject ():
938
941
"""CWLProv Research Object."""
939
942
940
- def __init__ (self , temp_prefix_ro = "tmp" , orcid = '' , full_name = '' ):
943
+ def __init__ (self , temp_prefix_ro = "tmp" , orcid = '' , full_name = '' , fsaccess = None ):
941
944
# type: (str, Text, Text) -> None
945
+ # type: Optional[StdFsAccess]
942
946
"""Initialize the ResearchObject."""
943
947
self .temp_prefix = temp_prefix_ro
944
948
self .orcid = '' if not orcid else _valid_orcid (orcid )
@@ -954,7 +958,7 @@ def __init__(self, temp_prefix_ro="tmp", orcid='', full_name=''):
954
958
self ._external_aggregates = [] # type: List[Dict[Text, Text]]
955
959
self .annotations = [] # type: List[Dict[Text, Any]]
956
960
self ._content_types = {} # type: Dict[Text,str]
957
-
961
+ self . fsaccess = fsaccess
958
962
# These should be replaced by generate_prov_doc when workflow/run IDs are known:
959
963
self .engine_uuid = "urn:uuid:%s" % uuid .uuid4 ()
960
964
self .ro_uuid = uuid .uuid4 ()
@@ -1553,8 +1557,7 @@ def _relativise_files(self, structure):
1553
1557
# Register in RO; but why was this not picked
1554
1558
# up by used_artefacts?
1555
1559
_logger .info ("[provenance] Adding to RO %s" , structure ["location" ])
1556
- fsaccess = StdFsAccess ("" )
1557
- with fsaccess .open (structure ["location" ], "rb" ) as fp :
1560
+ with self .fsaccess .open (structure ["location" ], "rb" ) as fp :
1558
1561
relative_path = self .add_data_file (fp )
1559
1562
checksum = PurePosixPath (relative_path ).name
1560
1563
structure ["checksum" ] = "%s$%s" % (SHA1 , checksum )
0 commit comments