Repository navigation
Expand file tree
/
Copy pathep3-init.rb
More file actions
executable file
·77 lines (69 loc) · 1.8 KB
/
Copy pathep3-init.rb
File metadata and controls
executable file
·77 lines (69 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env ruby
# coding: utf-8
require 'optparse'
require 'tmpdir'
require 'fileutils'
require 'uri'
require 'yaml'
require_relative 'init/cwl2wfnet'
require_relative 'runtime/inspector'
def ep3_init(args)
parser = OptionParser.new
parser.banner = "Usage: ep3 init [options] <cwl>"
parser.on('--target-dir=DIR')
parser.on('--force')
opts = parser.getopts(args)
unless args.length == 1
puts parser.help
exit
end
unless ENV.include? 'EP3_TEMPLATE_DIR'
raise 'EP3_TEMPLATE_DIR is necessary'
end
template_dir = ENV['EP3_TEMPLATE_DIR']
cwl = args.pop
file = case cwl
when /^(.+)#.+$/
$1
else
cwl
end
uri = URI.parse(file)
if (uri.scheme == 'file' or uri.scheme.nil?) and not File.exist?(uri.path)
raise "No such file: #{file}"
end
force = opts.fetch('force', false)
target_dir = if opts.include? 'target-dir'
dir = opts['target-dir']
if Dir.exist?(dir) and not force
raise "#{dir} already exist"
end
FileUtils.mkdir_p dir
File.expand_path(dir)
else
Dir.mktmpdir
end
dst = File.join(target_dir, 'workdir')
FileUtils.mkdir_p(dst) unless Dir.exist?(dst)
begin
nets = cwl2wfnet(cwl, dst)
nets.each{ |n|
open(File.join(n[:destination], 'job.yml'), 'w') { |f|
f.puts YAML.dump(n[:net].to_h)
}
}
FileUtils.cp(File.join(template_dir, 'root.yml'), dst)
rescue UnsupportedError => e
FileUtils.remove_entry(dst) if Dir.exist? dst
warn e
exit 33
rescue StandardError, CWLParseError, CWLInspectionError => e
FileUtils.remove_entry(dst) if Dir.exist? dst
raise e
end
puts target_dir
0
end
if $0 == __FILE__
ep3_init(ARGV)
end