Skip to content

Commit

Permalink
convert: add size and creation date to outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
simleo committed Nov 8, 2023
1 parent c27ed11 commit f6318b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/runcrate/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ def add_action_params(self, crate, activity, to_wf_p, ptype="usage"):
))
if len(action_p["exampleOfWork"]) == 1:
action_p["exampleOfWork"] = action_p["exampleOfWork"][0]
if ptype == "generation":
action_p["dateCreated"] = rel.time.isoformat()
action_params.append(action_p)
return action_params

Expand Down Expand Up @@ -606,6 +608,7 @@ def convert_param(self, prov_param, crate, convert_secondary=True, parent=None):
source = self.manifest[hash_]
action_p = crate.add_file(source, dest, properties={
"sha1": hash_,
"contentSize": str(Path(source).stat().st_size)
})
self._set_alternate_name(prov_param, action_p, parent=parent)
try:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_cwlprov_crate_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ def test_revsort(data_dir, tmpdir):
assert "File" in entity.type
assert entity["alternateName"] == "whale.txt"
assert entity["sha1"] == entity.id.rsplit("/")[-1]
assert entity["contentSize"] == "1111"
wf_input_file = entity
wf_output_file = wf_results[0]
assert wf_output_file["alternateName"] == "output.txt"
assert wf_output_file["sha1"] == wf_output_file.id.rsplit("/")[-1]
assert wf_output_file["dateCreated"] == "2018-10-25T15:46:38.058365"
assert wf_output_file["contentSize"] == "1111"
assert "File" in wf_output_file.type
steps = workflow["step"]
assert len(steps) == 2
Expand All @@ -118,6 +121,8 @@ def test_revsort(data_dir, tmpdir):
assert rev_input_file is wf_input_file
rev_output_file = results[0]
assert "File" in rev_output_file.type
assert rev_output_file["dateCreated"] == "2018-10-25T15:46:36.963254"
assert rev_output_file["contentSize"] == "1111"
assert step["position"] == "0"
assert set(_connected(step)) == set([
("packed.cwl#main/input", "packed.cwl#revtool.cwl/input"),
Expand Down Expand Up @@ -357,6 +362,7 @@ def test_dir_io(data_dir, tmpdir):
assert "Dataset" in entity.type
wf_input_dir = entity
wf_output_dir = wf_results[0]
assert wf_output_dir["dateCreated"] == "2023-02-17T16:20:30.288242"
assert wf_input_dir.type == wf_output_dir.type == "Dataset"
assert wf_input_dir["alternateName"] == "grepucase_in"
assert len(wf_input_dir["hasPart"]) == 2
Expand Down Expand Up @@ -395,6 +401,7 @@ def test_dir_io(data_dir, tmpdir):
assert greptool_input_dir is wf_input_dir
greptool_output_dir = greptool_results[0]
assert "Dataset" in greptool_output_dir.type
assert greptool_output_dir["dateCreated"] == "2023-02-17T16:20:30.262141"
ucasetool_action = action_map["packed.cwl#ucasetool.cwl"]
ucasetool_objects = ucasetool_action["object"]
ucasetool_results = ucasetool_action["result"]
Expand Down

0 comments on commit f6318b3

Please sign in to comment.