Skip to content

Commit d18d931

Browse files
authored
Merge pull request #488 from common-workflow-language/initialFileSizes
add size attribute to Files in the initial job object
2 parents f84ff04 + aaaa242 commit d18d931

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

appveyor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ test_script:
2626

2727
- "%CMD_IN_ENV% python setup.py test"
2828

29+
branches:
30+
only:
31+
- master

cwltool/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,19 @@ def pathToLoc(p):
591591
p["location"] = p["path"]
592592
del p["path"]
593593

594+
def addSizes(p):
595+
if 'location' in p:
596+
try:
597+
p["size"] = os.stat(p["location"][7:]).st_size # strip off file://
598+
except OSError:
599+
pass
600+
elif 'contents' in p:
601+
p["size"] = len(p['contents'])
602+
else:
603+
return # best effort
604+
594605
visit_class(job_order_object, ("File", "Directory"), pathToLoc)
606+
visit_class(job_order_object, ("File"), addSizes)
595607
adjustDirObjs(job_order_object, trim_listing)
596608
normalizeFilesDirs(job_order_object)
597609

cwltool/pathmapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def visit_class(rec, cls, op): # type: (Any, Iterable, Union[Callable[..., Any]
3737
"""Apply a function to with "class" in cls."""
3838

3939
if isinstance(rec, dict):
40-
if rec.get("class") in cls:
40+
if "class" in rec and rec.get("class") in cls:
4141
op(rec)
4242
for d in rec:
4343
visit_class(rec[d], cls, op)

0 commit comments

Comments
 (0)