Skip to content

Commit

Permalink
Add --[no-]compute-checksum option
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-tan committed May 12, 2021
1 parent aadb87f commit 702602c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
12 changes: 11 additions & 1 deletion ep3-runner
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ end

if $0 == __FILE__
extensions = []
compute_checksum = true
loglevel = Normal
keep_tmpdir_level = nil

Expand Down Expand Up @@ -101,6 +102,9 @@ if $0 == __FILE__
parser.on('--veryverbose', 'more verbose output') {
loglevel = VeryVerbose
}
parser.on('--[no-]compute-checksum', 'compute (or do not compute) checksum of contents (default: --compute-checksum)') { |cs|
compute_checksum = cs
}
parser.on('--extension=EXT', 'specify extension') { |ext|
extensions.push ext
}
Expand Down Expand Up @@ -178,7 +182,13 @@ if $0 == __FILE__
exit ret_run.fetch('return', 1)
end

ret_list = run_cmd("#{basedir}/ep3 list #{target_arg} --copy #{dst_arg}", loglevel)
copt = if compute_checksum
'--compute-checksum'
else
'--no-compute-checksum'
end

ret_list = run_cmd("#{basedir}/ep3 list #{target_arg} #{copt} --copy #{dst_arg}", loglevel)
if ret_list['success']
tmpdir_will_be_removed = true unless keep_tmpdir_level == LeaveAlways
exit 0
Expand Down
6 changes: 5 additions & 1 deletion lib/ep3/ep3-list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
require_relative 'runtime/stage-in'

def ep3_list(args)
compute_checksum = true
parser = OptionParser.new
parser.banner = "Usage: ep3 list [options]"
parser.on('--target-dir=DIR')
parser.on('--copy')
parser.on('--destination=DST')
parser.on('--[no-]compute-checksum') { |cs|
compute_checksum = cs
}

opts = parser.getopts(args)
unless args.empty?
Expand Down Expand Up @@ -44,7 +48,7 @@ def ep3_list(args)
v.nil?
}
puts JSON.dump(stagein(to_be_skipped, {}, output, dst,
opts.include?('copy')))
opts.include?('copy'), compute_checksum))
0
end

Expand Down
20 changes: 10 additions & 10 deletions lib/ep3/runtime/stage-in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
require 'securerandom'
require_relative 'inspector'

def stagein(to_be_skipped, staged_inputs, job, outdir, force_stagein = false)
def stagein(to_be_skipped, staged_inputs, job, outdir, force_stagein = false, compute_checksum = false)
Hash[job.each.map{ |k, v|
if to_be_skipped.call(k, v)
nil
elsif staged_inputs.include?(k)
[k, staged_inputs[k].to_h]
else
[k, stagein_(v, outdir, force_stagein).to_h]
[k, stagein_(v, outdir, force_stagein, compute_checksum).to_h]
end
}.compact]
end

def stagein_(obj, outdir, force_stagein = false)
def stagein_(obj, outdir, force_stagein = false, compute_checksum = false)
case obj
when CWLFile
if force_stagein or need_staging(obj)
Expand All @@ -38,9 +38,9 @@ def stagein_(obj, outdir, force_stagein = false)
end
ret.location = 'file://'+ret.path
ret.secondaryFiles = obj.secondaryFiles.map{ |sec|
stagein_(sec, outdir, true)
stagein_(sec, outdir, true, compute_checksum)
}
ret.evaluate(nil)
ret.evaluate(nil, false, compute_checksum)
else
obj
end
Expand All @@ -52,21 +52,21 @@ def stagein_(obj, outdir, force_stagein = false)
ret.location = 'file://'+ret.path
FileUtils.mkdir_p ret.path
ret.listing = obj.listing.map{ |lst|
stagein_(lst, ret.path, true)
stagein_(lst, ret.path, true, compute_checksum)
}
ret.evaluate(nil)
ret.evaluate(nil, false, compute_checksum)
else
obj
end
when CWLRecordValue
obj.fields.transform_values{ |v|
stagein_(v, outdir, force_stagein).to_h
stagein_(v, outdir, force_stagein, compute_checksum).to_h
}
when CWLUnionValue
stagein_(obj.value, outdir, force_stagein)
stagein_(obj.value, outdir, force_stagein, compute_checksum)
when Array
obj.map{ |o|
stagein_(o, outdir, force_stagein).to_h
stagein_(o, outdir, force_stagein, compute_checksum).to_h
}
else
obj
Expand Down

0 comments on commit 702602c

Please sign in to comment.