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
|
# File 'lib/tumugi/command/show.rb', line 13
def execute(dag, options={})
out = options[:out]
if out
ext = File.extname(options[:out])
format = ext[1..-1] if ext.start_with?('.')
raise "#{format} is not supported format" unless @@supported_formats.include?(format)
else
format = options[:format]
end
g = GraphViz.new(:G, type: :digraph, rankdir: "RL")
tasks = dag.tsort
tasks.each do |task|
g.add_nodes(task.id.to_s)
end
tasks.each do |task|
list(task._requires).each do |req|
g.add_edge(g.get_node(req.id.to_s), g.get_node(task.id.to_s))
end
end
if out
logger.info "output result to #{out}"
FileUtils.mkdir_p(File.dirname(out))
if format == 'dot'
File.write(out, g.to_s)
else
g.output(format => out)
end
else
print g
end
return true
end
|